Loading...
Loading...
Compare original and translation side by side
SfTreeGridSyncfusion.UI.Xaml.TreeGridSyncfusion.Grid.WinUISfTreeGridSyncfusion.UI.Xaml.TreeGridSyncfusion.Grid.WinUI<Window
x:Class="TreeGridDemo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:treeGrid="using:Syncfusion.UI.Xaml.TreeGrid">
<Window.DataContext>
<local:ViewModel/>
</Window.DataContext>
<Grid>
<treeGrid:SfTreeGrid x:Name="treeGrid"
ItemsSource="{Binding Employees}"
ParentPropertyName="ID"
ChildPropertyName="ReportsTo"
SelfRelationRootValue="-1"
AutoExpandMode="RootNodesExpanded" />
</Grid>
</Window>public class EmployeeInfo
{
public int ID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Title { get; set; }
public double Salary { get; set; }
public int ReportsTo { get; set; }
}
public class ViewModel
{
public ObservableCollection<EmployeeInfo> Employees { get; set; }
public ViewModel()
{
Employees = new ObservableCollection<EmployeeInfo>
{
new EmployeeInfo { ID = 1, FirstName = "John", LastName = "Doe",
Title = "CEO", Salary = 200000, ReportsTo = -1 },
new EmployeeInfo { ID = 2, FirstName = "Jane", LastName = "Smith",
Title = "Manager", Salary = 120000, ReportsTo = 1 },
new EmployeeInfo { ID = 3, FirstName = "Bob", LastName = "Johnson",
Title = "Developer", Salary = 80000, ReportsTo = 2 }
};
}
}<Window
x:Class="TreeGridDemo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:treeGrid="using:Syncfusion.UI.Xaml.TreeGrid">
<Window.DataContext>
<local:ViewModel/>
</Window.DataContext>
<Grid>
<treeGrid:SfTreeGrid x:Name="treeGrid"
ItemsSource="{Binding Employees}"
ParentPropertyName="ID"
ChildPropertyName="ReportsTo"
SelfRelationRootValue="-1"
AutoExpandMode="RootNodesExpanded" />
</Grid>
</Window>public class EmployeeInfo
{
public int ID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Title { get; set; }
public double Salary { get; set; }
public int ReportsTo { get; set; }
}
public class ViewModel
{
public ObservableCollection<EmployeeInfo> Employees { get; set; }
public ViewModel()
{
Employees = new ObservableCollection<EmployeeInfo>
{
new EmployeeInfo { ID = 1, FirstName = "John", LastName = "Doe",
Title = "CEO", Salary = 200000, ReportsTo = -1 },
new EmployeeInfo { ID = 2, FirstName = "Jane", LastName = "Smith",
Title = "Manager", Salary = 120000, ReportsTo = 1 },
new EmployeeInfo { ID = 3, FirstName = "Bob", LastName = "Johnson",
Title = "Developer", Salary = 80000, ReportsTo = 2 }
};
}
}public class PersonInfo
{
public string FirstName { get; set; }
public string LastName { get; set; }
public double Salary { get; set; }
public ObservableCollection<PersonInfo> Children { get; set; }
}<treeGrid:SfTreeGrid x:Name="treeGrid"
ItemsSource="{Binding PersonDetails}"
ChildPropertyName="Children" />public class PersonInfo
{
public string FirstName { get; set; }
public string LastName { get; set; }
public double Salary { get; set; }
public ObservableCollection<PersonInfo> Children { get; set; }
}<treeGrid:SfTreeGrid x:Name="treeGrid"
ItemsSource="{Binding PersonDetails}"
ChildPropertyName="Children" />// Each employee has an ID and ReportsTo (parent ID)
ParentPropertyName = "ID"
ChildPropertyName = "ReportsTo"
SelfRelationRootValue = -1 // Root nodes have ReportsTo = -1// Each employee has an ID and ReportsTo (parent ID)
ParentPropertyName = "ID"
ChildPropertyName = "ReportsTo"
SelfRelationRootValue = -1 // Root nodes have ReportsTo = -1// Each person has a Children property containing child objects
ChildPropertyName = "Children"
// No ParentPropertyName needed// Each person has a Children property containing child objects
ChildPropertyName = "Children"
// No ParentPropertyName needed<!-- Auto-generate columns from data properties -->
<treeGrid:SfTreeGrid AutoGenerateColumns="True" />
<!-- Define columns manually for full control -->
<treeGrid:SfTreeGrid AutoGenerateColumns="False">
<treeGrid:SfTreeGrid.Columns>
<treeGrid:TreeGridTextColumn MappingName="FirstName" HeaderText="First Name"/>
<treeGrid:TreeGridNumericColumn MappingName="Salary" DisplayNumberFormat="C2"/>
</treeGrid:SfTreeGrid.Columns>
</treeGrid:SfTreeGrid><!-- Auto-generate columns from data properties -->
<treeGrid:SfTreeGrid AutoGenerateColumns="True" />
<!-- Define columns manually for full control -->
<treeGrid:SfTreeGrid AutoGenerateColumns="False">
<treeGrid:SfTreeGrid.Columns>
<treeGrid:TreeGridTextColumn MappingName="FirstName" HeaderText="First Name"/>
<treeGrid:TreeGridNumericColumn MappingName="Salary" DisplayNumberFormat="C2"/>
</treeGrid:SfTreeGrid.Columns>
</treeGrid:SfTreeGrid>public class ViewModel : INotifyPropertyChanged
{
private ObservableCollection<DataModel> _items;
public ObservableCollection<DataModel> Items
{
get => _items;
set
{
_items = value;
OnPropertyChanged();
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string name = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
}public class ViewModel : INotifyPropertyChanged
{
private ObservableCollection<DataModel> _items;
public ObservableCollection<DataModel> Items
{
get => _items;
set
{
_items = value;
OnPropertyChanged();
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string name = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
}// Auto-expand modes
AutoExpandMode = AutoExpandMode.AllNodesExpanded; // All expanded
AutoExpandMode = AutoExpandMode.RootNodesExpanded; // Only root
AutoExpandMode = AutoExpandMode.None; // All collapsed
// Programmatic control
treeGrid.ExpandNode(node);
treeGrid.CollapseNode(node);
treeGrid.ExpandAllNodes();
treeGrid.CollapseAllNodes();// Auto-expand modes
AutoExpandMode = AutoExpandMode.AllNodesExpanded; // All expanded
AutoExpandMode = AutoExpandMode.RootNodesExpanded; // Only root
AutoExpandMode = AutoExpandMode.None; // All collapsed
// Programmatic control
treeGrid.ExpandNode(node);
treeGrid.CollapseNode(node);
treeGrid.ExpandAllNodes();
treeGrid.CollapseAllNodes();ParentPropertyName = "EmployeeID"
ChildPropertyName = "ManagerID"ParentPropertyName = "EmployeeID"
ChildPropertyName = "ManagerID"ChildPropertyName = "SubItems" // Nested collectionChildPropertyName = "SubItems" // Nested collectionChildPropertyName = "SubCategories"ChildPropertyName = "SubCategories"ParentPropertyName = "PartID"
ChildPropertyName = "ParentPartID"ParentPropertyName = "PartID"
ChildPropertyName = "ParentPartID"ChildPropertyName = "SubTasks"ChildPropertyName = "SubTasks"ChildPropertyName = "Children"ChildPropertyName = "Children"