Skip to content

SyncfusionExamples/How-to-autofit-item-height-based-on-content-in-wpf-treeview

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

How to Autofit Item Height Based on Content in WPF TreeView?

This repository describes how to autofit item height based on content in WPF TreeView (SfTreeView).

The TreeView allows adjusting height of items based on the content measured size while loaded by setting the Height argument with value returned from QueryNodeSizeEventArgs.GetAutoFitNodeHeight method.

XAML

<syncfusion:SfTreeView x:Name="sfTreeView"
                       Margin="10"
                       QueryNodeSize="SfTreeView_QueryNodeSize"    
                       ExpandActionTrigger="Node"
                       ItemsSource="{Binding Menu}" />

C#

sfTreeView.QueryNodeSize += SfTreeView_QueryNodeSize;

private void SfTreeView_QueryNodeSize(object sender, Syncfusion.UI.Xaml.TreeView.QueryNodeSizeEventArgs e)
{
    if (e.Node.Level == 0)
    {
        //Returns specified item height for items.
        e.Height = 30;
        e.Handled = true;
    }
    else
    {
        // Returns item height based on the content loaded.
        e.Height = e.GetAutoFitNodeHeight();
        e.Handled = true;
    }
}

TreeView with modified the item height based on the content

About

This repository describes how to autofit item height based on content in wpf treeview

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 6

Languages