Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added BindButtonCommand.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# how-to-bind-button-command-to-view-model-in-wpf-and-uwp-treegrid-in-mvvm
# How to Bind Button Command to ViewModel in WPF / UWP TreeGrid in MVVM?

This example illustrates to bind the button command to ViewModel in treegrid.
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).

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.

In the following example, ViewModel command receives the underlying data object as command parameter, since the DataContext is bound as command parameter.

### XAML:
``` xml
<syncfusion:TreeGridTemplateColumn MappingName="Title"
syncfusion:FocusManagerHelper.WantsKeyInput="True">
<syncfusion:TreeGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="Click" syncfusion:FocusManagerHelper.FocusedElement="True"
Command="{Binding Path=DataContext.RowDataCommand,ElementName=treeGrid}"
CommandParameter="{Binding}"/>
</DataTemplate>
</syncfusion:TreeGridTemplateColumn.CellTemplate>
</syncfusion:TreeGridTemplateColumn>
```

![Bind button command to viewmodel](BindButtonCommand.png)