.NET MAUI TreeView Load Children on Demand
The Load Children on Demand feature optimizes the performance of the Telerik UI for .NET MAUI TreeView control when operating with a huge amount of items. This mechanism lets the nodes load their child nodes as the user expands the parent by clicking on the expand icon for desktop and tapping on the item on mobile.
To enable the TreeView Load Children on Demand feature:
1. Set the IsLoadChildrenOnDemandEnabled
(bool
) property. The property specifies a value indicating whether load on demand is enabled.
2. Use the LoadChildrenOnDemand
event or LoadChildrenOnDemandCommand
command to load the items.
Load Children on Demand and Recursive CheckBox Mode
Consider the following scenarios when using the TreeView LoadChildrenOnDemand
feature in a combination with the Recursive
CheckBoxMode
:
- When checking the checkbox element of the parent item without loading the children, this parent item is added to the
CheckedItems
collection (the children are not). - When loading the children of the parent node by pressing the expand icon, and the checkbox of the parent node is checked, all child data items must be manually added to the
CheckedItems
collection.
Event
The TreeView exposes the following event for loading children on demand.
-
LoadChildrenOnDemand
—Raised when loading an item on demand. TheLoadChildrenOnDemand
event handler receives two parameters:- The
sender
argument, which is of typeobject
, but can be cast to theRadTreeView
type. - A
TreeViewLoadChildrenOnDemandEventArgs
object, which has a reference to:- the item through its
Item
(object
) property.
- the item through its
- The
Command
The TreeView exposes the following command for loading children on demand.
-
LoadChildrenOnDemandCommand
—Specifies a command to execute when loading an item on demand. The command accepts a parameter of typeTelerik.Maui.Controls.TreeView.TreeViewLoadChildrenOnDemandCommandContext
.
The next example shows how to use the Load Children on Demand command in the TreeView.
1. Define the TreeView control:
2. Add a sample data model:
3. Define the ViewModel with the LoadChildrenOnDemandCommand
implementation:
For runnable examples demonstrating the TreeView Load Children on Demand command, see the SDKBrowser Demo Application and go to TreeView > Load Children on Demand.