Skip to content

Commit 7e2c02f

Browse files
authored
Merge pull request #3 from SyncfusionExamples/ES-975464
ES-975464 - Resolve ReadMe length Issues in this Repository
2 parents 78da3e2 + 2e98be3 commit 7e2c02f

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

README.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,44 @@
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?
22

3-
This example illustrates to bind the SelectedItem property from ViewModel to 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+
5+
You can bind the **SelectedItem** property directly to TreeGrid by setting the **SfTreeGrid.SelectedItem** property.
6+
7+
### XAML:
8+
9+
``` xml
10+
<syncfusion:SfTreeGrid Name="treeGrid"
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"/>
21+
22+
```
23+
24+
### C#:
25+
26+
``` C#
27+
public class ViewModel: NotificationObject
28+
{
29+
private object selectedItem;
30+
31+
public object SelectedItem
32+
{
33+
get
34+
{
35+
return selectedItem;
36+
}
37+
set
38+
{
39+
selectedItem = value;
40+
RaisePropertyChanged("SelectedItem");
41+
}
42+
}
43+
}
44+
```

0 commit comments

Comments
 (0)