TreeView Does Not Resize After Item Collapses or Expands

Environment

Product Version 2019.3.1023.1
Product TreeView for Xamarin

Description

The RadTreeView doesn't automatically resize itself every time an item is expanded or collapsed.

Solution

You can solve this by asking Xamarin.Forms to resize the TreeView by calling InvalidateMeasureNonVirtual after an item is expanded or collapsed.

Step 1

Subscribe to the RadTreeView's ItemExpanded and ItemCollapsed events

XAML

<telerikDataControls:RadTreeView x:Name="MyTreeView"
                                 ItemExpanded="TreeView_OnItemExpanded"
                                 ItemCollapsed="TreeView_OnItemCollapsed"
                                 VerticalOptions="Start">

Code-Behind

private void TreeView_OnItemExpanded(object sender, TreeViewItemEventArgs e)
{
}

private void TreeView_OnItemCollapsed(object sender, TreeViewItemEventArgs e)
{
}

Step 2

Invoke InvalidateMeasureNonVirtual with the InvalidationTrigger.MeasureChanged argument on the RadTreeView.

private void TreeView_OnItemExpanded(object sender, TreeViewItemEventArgs e)
{
    MyTreeView.InvalidateMeasureNonVirtual(InvalidationTrigger.MeasureChanged);
}

private void TreeView_OnItemCollapsed(object sender, TreeViewItemEventArgs e)
{
    MyTreeView.InvalidateMeasureNonVirtual(InvalidationTrigger.MeasureChanged);
}
In this article
Not finding the help you need? Improve this article