Skip to content

SyncfusionExamples/autofit-treeview-node-xamarin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

How to AutoFit the nodes based on the content in Xamarin.Forms TreeView (SfTreeView)

You can auto fit the SfTreeView node height based on its content using QueryNodeSize in Xamarin.Forms.

You can also refer th following article.

https://www.syncfusion.com/kb/11418/how-to-autofit-the-nodes-based-on-the-content-in-xamarin-forms-treeview-sftreeview

C#

Setting node height based on its content using GetActualNodeHeight method.

namespace TreeViewXamarin
{
    public class Behavior : Behavior<SfTreeView>
    {
        protected override void OnAttachedTo(SfTreeView bindable)
        {
            bindable.QueryNodeSize += Bindable_QueryNodeSize;
            base.OnAttachedTo(bindable);
        }
 
        private void Bindable_QueryNodeSize(object sender, QueryNodeSizeEventArgs e)
        {
            // Returns item height based on the content loaded.
            e.Height = e.GetActualNodeHeight();
            e.Handled = true;
        }
        protected override void OnDetachingFrom(SfTreeView bindable)
        {
            bindable.QueryNodeSize -= Bindable_QueryNodeSize;
            base.OnDetachingFrom(bindable);
        }
    }
}

Output

AutoFitContentTreeView

About

This repository contains sample about how to AutoFit the nodes based on the content in Xamarin.Forms TreeView (SfTreeView)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages