|
1 | | -# how-to-bind-the-SelectedItem-property-of-wpf-tree-grid-in-mvvm |
| 1 | +# How to Bind the SelectedItem Property of WPF TreeGrid in MVVM? |
2 | 2 |
|
3 | | -This example illustrates to bind the `SelectedItem` property from ViewModel to the [SelectedItem](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Grid.SfGridBase.html#Syncfusion_UI_Xaml_Grid_SfGridBase_SelectedItem) Property of [WPF TreeGrid](https://www.syncfusion.com/wpf-controls/treegrid) and [UWP TreeGrid](https://www.syncfusion.com/uwp-ui-controls/treegrid). |
| 3 | +This example illustrates to bind the **SelectedItem** property from ViewModel to the [SelectedItem](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Grid.SfGridBase.html#Syncfusion_UI_Xaml_Grid_SfGridBase_SelectedItem) Property of [WPF TreeGrid](https://www.syncfusion.com/wpf-controls/treegrid) and [UWP TreeGrid](https://www.syncfusion.com/uwp-ui-controls/treegrid) (SfTreeGrid). |
4 | 4 |
|
5 | | -You can bind the `SelectedItem` property directly to `TreeGrid` by setting the [SfTreeGrid.SelectedItem](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Grid.SfGridBase.html#Syncfusion_UI_Xaml_Grid_SfGridBase_SelectedItem) property. |
| 5 | +You can bind the **SelectedItem** property directly to TreeGrid by setting the **SfTreeGrid.SelectedItem** property. |
6 | 6 |
|
7 | | -## XAML code: |
| 7 | +### XAML: |
8 | 8 |
|
9 | 9 | ``` xml |
10 | 10 | <syncfusion:SfTreeGrid Name="treeGrid" |
11 | | - Grid.Row="1" |
12 | | - ChildPropertyName="ReportsTo" |
13 | | - AutoExpandMode="AllNodesExpanded" |
14 | | - ShowRowHeader="True" |
15 | | - SelectedItem="{Binding SelectedItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" |
16 | | - AutoGenerateColumns="False" |
17 | | - ItemsSource="{Binding Employees}" |
18 | | - ParentPropertyName="ID" |
19 | | - SelfRelationRootValue="-1"/> |
| 11 | + Grid.Row="1" |
| 12 | + ChildPropertyName="ReportsTo" |
| 13 | + AutoExpandMode="AllNodesExpanded" |
| 14 | + ShowRowHeader="True" |
| 15 | + SelectedItem="{Binding SelectedItem, Mode=TwoWay, |
| 16 | + UpdateSourceTrigger=PropertyChanged}" |
| 17 | + AutoGenerateColumns="False" |
| 18 | + ItemsSource="{Binding Employees}" |
| 19 | + ParentPropertyName="ID" |
| 20 | + SelfRelationRootValue="-1"/> |
20 | 21 |
|
21 | 22 | ``` |
22 | 23 |
|
23 | | -## C# code: |
| 24 | +### C#: |
24 | 25 |
|
25 | 26 | ``` C# |
26 | 27 | public class ViewModel: NotificationObject |
|
0 commit comments