Skip to content

Commit ab29d94

Browse files
authored
Merge pull request #2 from SyncfusionExamples/ES-975464
ES-975464 - Resolve ReadMe Length issue in this repository
2 parents 5288045 + dbd5a4c commit ab29d94

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

BindButtonCommand.png

118 KB
Loading

README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1-
# how-to-bind-button-command-to-view-model-in-wpf-and-uwp-treegrid-in-mvvm
1+
# How to Bind Button Command to ViewModel in WPF / UWP TreeGrid in MVVM?
22

3-
This example illustrates to bind the button command to ViewModel in treegrid.
3+
This example illustrates to bind the Button command to ViewModel in [WPF TreeGrid](https://www.syncfusion.com/wpf-controls/treegrid) and [UWP TreeGrid](https://www.syncfusion.com/uwp-ui-controls/treegrid) (SfTreeGrid).
4+
5+
You can load a button for the columns in TreeGrid using [TreeGridTemplateColumn](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.TreeGrid.TreeGridTemplateColumn.html). When loading the buttons, you can bind a command in ViewModel using ElementName binding.
6+
7+
In the following example, ViewModel command receives the underlying data object as command parameter, since the DataContext is bound as command parameter.
8+
9+
### XAML:
10+
``` xml
11+
<syncfusion:TreeGridTemplateColumn MappingName="Title"
12+
syncfusion:FocusManagerHelper.WantsKeyInput="True">
13+
<syncfusion:TreeGridTemplateColumn.CellTemplate>
14+
<DataTemplate>
15+
<Button Content="Click" syncfusion:FocusManagerHelper.FocusedElement="True"
16+
Command="{Binding Path=DataContext.RowDataCommand,ElementName=treeGrid}"
17+
CommandParameter="{Binding}"/>
18+
</DataTemplate>
19+
</syncfusion:TreeGridTemplateColumn.CellTemplate>
20+
</syncfusion:TreeGridTemplateColumn>
21+
```
22+
23+
![Bind button command to viewmodel](BindButtonCommand.png)

0 commit comments

Comments
 (0)