Skip to content

This repository contains the sample which demonstrates how to autofit the TreeView item height based on its content size

Notifications You must be signed in to change notification settings

SyncfusionExamples/Xamarin-TreeView-Item-Height-Customization

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

How to autofit the items based on the content in Xamarin Forms TreeView?

In TreeView, you can customize each item size by using the QueryNodeSize event. In this event, the Handled property indicates whether to set specified size for an item or not by its Boolean value. This event is raised when an item comes in view with the QueryNodeSizeEventArgs argument.

<ContentPage xmlns:syncfusion="clr-namespace:Syncfusion.XForms.TreeView;assembly=Syncfusion.SfTreeView.XForms"
             xmlns:local="clr-namespace:GettingStarted"
             x:Class="GettingStarted.MainPage">
    <ContentPage.BindingContext>
       <local:FileManagerViewModel x:Name="viewModel"></local:FileManagerViewModel>
    </ContentPage.BindingContext>
    <ContentPage.Content>
       <syncfusion:SfTreeView x:Name="treeView"
                              QueryNodeSize="TreeView_QueryNodeSize"
                              ChildPropertyName="SubFiles"
                              ItemsSource="{Binding ImageNodeInfo}"/>
       </syncfusion:SfTreeView>
    </ContentPage.Content>
</ContentPage>

The QueryNodeSizeEventArgs.GetActualNodeHeight method of QueryNodeSizeEventArgs is used to get the measured height of the item based on content and it is set to the QueryNodeSizeEventArgs.Height property.

private void TreeView_QueryNodeSize(object sender, QueryNodeSizeEventArgs e)
{
    if (e.Node.Level == 0)
    {
        //Returns speified item height for item.
        e.Height = 200;
        e.Handled = true;
    }
    else
    {
        // Returns measured height based on the content loaded.
        e.Height = e.GetActualNodeHeight();
        e.Handled = true;
    }
}

About

This repository contains the sample which demonstrates how to autofit the TreeView item height based on its content size

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •