New to Telerik UI for .NET MAUI? Start a free 30-day trial

Commands

The .NET MAUI TreeView provides various commands that allow you to initiate expand or collapse actions, check and uncheck actions, and to scroll to a specific item.

Expanding and Collapsing Items

TreeView exposes the following commands for expanding and collapsing all items:

  • ExpandAllCommand(ICommand)—Gets a command to expand all items in the control.
  • CollapseAllCommand(ICommand)—Gets a command to collapse all items in the control.
<Grid RowDefinitions="Auto,*">
    <HorizontalStackLayout Spacing="10">
        <Button Text="ExpandAll" Command="{Binding ExpandAllCommand, Source={x:Reference treeView}}"/>
        <Button Text="CollapseAll" Command="{Binding CollapseAllCommand, Source={x:Reference treeView}}"/>
    </HorizontalStackLayout>
    <telerik:RadTreeView x:Name="treeView" Grid.Row="1" ItemsSource="{Binding Items}">
        <telerik:TreeViewDescriptor DisplayMemberPath="Name"
                                    ItemsSourcePath="Children"
                                    TargetType="{x:Type local:Item}" />
        <telerik:RadTreeView.BindingContext>
            <local:ViewModel/>
        </telerik:RadTreeView.BindingContext>
    </telerik:RadTreeView>
</Grid>

.NET MAUI TreeView Expand and Collapse

For a runnable example demonstrating the TreeView Expand and Collapse commands, see the SDKBrowser Demo Application and go to TreeView > Commands.

Checking and Unchecking Items

TreeView exposes the following commands for checking and unchecking all items:

  • CheckAllCommand(ICommand)—Gets a command to check all items in the control.
  • UncheckAllCommand(ICommand)—Gets a command to uncheck all items in the control.
<Grid RowDefinitions="Auto,*">
    <HorizontalStackLayout Spacing="10">
        <Button Text="CheckAll" Command="{Binding CheckAllCommand, Source={x:Reference treeView}}"/>
        <Button Text="Uncheckall" Command="{Binding UncheckAllCommand, Source={x:Reference treeView}}"/>
    </HorizontalStackLayout>
    <telerik:RadTreeView x:Name="treeView" 
                         Grid.Row="1" 
                         ItemsSource="{Binding Items}" 
                         CheckBoxMode="Recursive">
        <telerik:TreeViewDescriptor DisplayMemberPath="Name"
                                    ItemsSourcePath="Children"
                                    TargetType="{x:Type local:Item}" />
        <telerik:RadTreeView.BindingContext>
            <local:ViewModel/>
        </telerik:RadTreeView.BindingContext>
    </telerik:RadTreeView>
</Grid>

.NET MAUI TreeView Check and Uncheck

For a runnable example demonstrating the TreeView Check and Uncheck commands, see the SDKBrowser Demo Application and go to TreeView > Commands.

Scrolling

TreeView exposes the following command that allows you to control the scrolling within the component:

  • ScrollToCommand(ICommand)—Gets a command that scrolls to an item in the control, which is specified as a parameter.

See Also

In this article