How To Bind The Selecteditem Property Of WPF Treegrid In MVVM?
mvvm
uwp
uwp-multicolumn-treeview
uwp-treegrid
wpf
wpf-multicolumn-treeview
wpf-treegrid
This example illustrates to bind the SelectedItem property from ViewModel to the SelectedItem Property of WPF TreeGrid and UWP TreeGrid (SfTreeGrid).
You can bind the SelectedItem property directly to TreeGrid by setting the SfTreeGrid.SelectedItem property.
XAML:
<syncfusion:SfTreeGrid Name="treeGrid"
Grid.Row="1"
ChildPropertyName="ReportsTo"
AutoExpandMode="AllNodesExpanded"
ShowRowHeader="True"
SelectedItem="{Binding SelectedItem, Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}"
AutoGenerateColumns="False"
ItemsSource="{Binding Employees}"
ParentPropertyName="ID"
SelfRelationRootValue="-1"/>
C#:
public class ViewModel: NotificationObject
{
private object selectedItem;
public object SelectedItem
{
get
{
return selectedItem;
}
set
{
selectedItem = value;
RaisePropertyChanged("SelectedItem");
}
}
}