.NET MAUI TreeView Item Hierarchy
To specify the data items' hierarchy and how each item is visualized, use the TreeViewDescriptor
class. For more flexibility, you can define multiple descriptors in the TreeView.
The TreeViewDescriptor
class exposes the following properties:
Property | Description |
---|---|
TargetType (System.Type ) |
Specifies the type of the data item the descriptor refers to. |
IdentityMemberPath (string ) |
Specifies the path to the identity member of the data item. The identifier member is used to identify the item in the hierarchy. If the property is not specified, the entire item is used instead. |
DisplayMemberPath (string ) |
Specifies the path to the display member of the data item. The display member is used to visualize the item on the screen. If the property is not specified, the entire item is used instead. |
ItemsSourcePath (string ) |
Specifies the path to the child items source of the data item. |
ItemTemplate (DataTemplate ) |
Specifies the template applied to the respective type of items. |
ItemStyle (Style with a target type of TreeViewItemView ) |
Specifies the style of the TreeView items. |
You can define multiple descriptors in the TreeView.
Here is an example demonstrating how to define the data items' hierarchy by using the TreeView descriptor:
1. Set up the RadTreeView
instance:
2. Add the telerik
namespaces:
3. Create a sample Item
class:
4. Add the ViewModel
class:
5. Register the Telerik controls through the Telerik.Maui.Controls.Compatibility.UseTelerik
extension method called inside the CreateMauiApp
method of the MauiProgram.cs
file of your project: