Skip to content

SyncfusionExamples/how-to-bind-the-SelectedItem-property-of-wpf-and-uwp-tree-grid-in-mvvm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 

Repository files navigation

How to Bind the SelectedItem Property of WPF TreeGrid in MVVM?

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");
        }
    }
}

About

This example explains about how to bind the selecteditem property of wpf and uwp treegrid in mvvm pattern

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 5

Languages