Skip to content

SyncfusionExamples/how-to-bind-button-command-to-view-model-in-wpf-and-uwp-treegrid-in-mvvm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

How to Bind Button Command to ViewModel in WPF / UWP TreeGrid in MVVM?

This example illustrates to bind the Button command to ViewModel in WPF TreeGrid and UWP TreeGrid (SfTreeGrid).

You can load a button for the columns in TreeGrid using TreeGridTemplateColumn. 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:

<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

About

This example illustrates to bind the button command to ViewModel in treegrid

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages