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.
<syncfusion:SfTreeView x:Name="sfTreeView"
Margin="10"
QueryNodeSize="SfTreeView_QueryNodeSize"
ExpandActionTrigger="Node"
ItemsSource="{Binding Menu}" />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;
}
}