menu

MAUI

  • User Guide
  • Demos
  • Support
  • Forums
  • Download
Class SfTreeView - MAUI API Reference | Syncfusion

    Show / Hide Table of Contents

    Class SfTreeView

    The SfTreeView control displays the hierarchical data in a tree-like structure with expand and collapse node options.

    Inheritance
    System.Object
    SfView
    SfTreeView
    Implements
    IDrawableLayout
    Microsoft.Maui.Graphics.IDrawable
    Microsoft.Maui.IAbsoluteLayout
    Microsoft.Maui.ILayout
    Microsoft.Maui.IView
    Microsoft.Maui.IElement
    Microsoft.Maui.ITransform
    Microsoft.Maui.IContainer
    System.Collections.Generic.IList<Microsoft.Maui.IView>
    System.Collections.Generic.ICollection<Microsoft.Maui.IView>
    System.Collections.Generic.IEnumerable<Microsoft.Maui.IView>
    System.Collections.IEnumerable
    Microsoft.Maui.ISafeAreaView
    Microsoft.Maui.IPadding
    Microsoft.Maui.ICrossPlatformLayout
    Microsoft.Maui.IVisualTreeElement
    Inherited Members
    SfView.ArrangeOverride(Rect)
    SfView.Children
    SfView.ClipToBounds
    SfView.GetSemanticsNodesCore(Double, Double)
    SfView.IDrawableLayout.DrawingOrder
    SfView.IDrawableLayout.InvalidateDrawable()
    SfView.MeasureOverride(Double, Double)
    SfView.OnBindingContextChanged()
    SfView.OnDraw(ICanvas, RectF)
    SfView.OnHandlerChanged()
    SfView.Padding
    Namespace: Syncfusion.Maui.TreeView
    Assembly: Syncfusion.Maui.TreeView.dll
    Syntax
    public class SfTreeView : SfView, IDrawableLayout, IDrawable, IAbsoluteLayout, ILayout, IView, IElement, ITransform, IContainer, IList<IView>, ICollection<IView>, IEnumerable<IView>, IEnumerable, ISafeAreaView, IPadding, ICrossPlatformLayout, IVisualTreeElement, ISemanticsProvider, ITreeCollectionView, IKeyboardListener, IParentThemeElement, IThemeElement
    Examples

    The following example demonstrates how to initialize and use the SfTreeView.

    using System.Collections.ObjectModel;
    using Syncfusion.Maui.TreeView;
    

    namespace TreeView {

    class FileManager {

    public string FileName { get; set; } public ObservableCollection SubFiles { get; set; }

    public FileManager(string fileName, ObservableCollection

    subfiles = null) { FileName = fileName; SubFiles = subfiles; }

    }

    class MainPage : ContentPage {

    public MainPage() {

    // Define some data. List fileInfo = new List() { new FileManager("Local Disk (C:)", new ObservableCollection(){ new FileManager("Program files")}), new FileManager("Load Disk (D:)", new ObservableCollection() { new FileManager("Personals") }), };

    // Initializes the SfTreeView SfTreeView treeView = new SfTreeView { // Source of the data ItemsSource = fileInfo, ChildPropertyName = "SubFiles",

    // Define the template for displaying each item ItemTemplate = new DataTemplate(() => { // Create a view with bindings for displaying each property. Label fileNameLabel = new Label() { FontSize = 18 }; fileNameLabel.SetBinding(Label.TextProperty, "FileName");

    // returns a ViewCell return new ViewCell { View = new StackLayout { Children = { fileNameLabel } } }; }) };

    this.Content = treeView; } } }

    Constructors

    SfTreeView()

    Initializes a new instance of the SfTreeView class.

    Declaration
    public SfTreeView()

    Fields

    AutoExpandModeProperty

    Identifies the AutoExpandMode bindable property.

    Declaration
    public static readonly BindableProperty AutoExpandModeProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    This bindable property is read-only.

    CheckBoxModeProperty

    Identifies the CheckBoxMode bindable property.

    Declaration
    public static readonly BindableProperty CheckBoxModeProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    This bindable property is read-only.

    CheckedItemsProperty

    Identifies the CheckedItems bindable property.

    Declaration
    public static readonly BindableProperty CheckedItemsProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    This bindable property is read-only.

    ChildPropertyNameProperty

    Identifies the ChildPropertyName bindable property.

    Declaration
    public static readonly BindableProperty ChildPropertyNameProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    This bindable property is read-only.

    CollapseCommandProperty

    Identifies the CollapseCommand bindable property.

    Declaration
    public static readonly BindableProperty CollapseCommandProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    This bindable property is read-only.

    CurrentItemProperty

    Identifies the CurrentItem bindable property.

    Declaration
    public static readonly BindableProperty CurrentItemProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    This bindable property is read-only.

    EnableHorizontalScrollingProperty

    Identifies the EnableHorizontalScrolling bindable property.

    Declaration
    public static readonly BindableProperty EnableHorizontalScrollingProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    This bindable property is read-only.

    ExpandActionTargetProperty

    Identifies the ExpandActionTarget bindable property.

    Declaration
    public static readonly BindableProperty ExpandActionTargetProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    This bindable property is read-only.

    ExpandCommandProperty

    Identifies the ExpandCommand bindable property.

    Declaration
    public static readonly BindableProperty ExpandCommandProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    This bindable property is read-only.

    ExpanderPositionProperty

    Identifies the ExpanderPosition bindable property.

    Declaration
    public static readonly BindableProperty ExpanderPositionProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    This bindable property is read-only.

    ExpanderTemplateProperty

    Identifies the ExpanderTemplate bindable property.

    Declaration
    public static readonly BindableProperty ExpanderTemplateProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    This bindable property is read-only.

    ExpanderWidthProperty

    Identifies the ExpanderWidth bindable property.

    Declaration
    public static readonly BindableProperty ExpanderWidthProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    This bindable property is read-only.

    FullRowSelectProperty

    Identifies the FullRowSelect bindable property.

    Declaration
    public static readonly BindableProperty FullRowSelectProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    This bindable property is read-only.

    HierarchyPropertyDescriptorsProperty

    Identifies the HierarchyPropertyDescriptors bindable property.

    Declaration
    public static readonly BindableProperty HierarchyPropertyDescriptorsProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    This bindable property is read-only.

    IndentationProperty

    Identifies the Indentation bindable property.

    Declaration
    public static readonly BindableProperty IndentationProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    This bindable property is read-only.

    IsAnimationEnabledProperty

    Identifies the IsAnimationEnabled bindable property.

    Declaration
    public static readonly BindableProperty IsAnimationEnabledProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    This bindable property is read-only.

    ItemHeightProperty

    Identifies the ItemHeight bindable property.

    Declaration
    public static readonly BindableProperty ItemHeightProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    This bindable property is read-only.

    ItemsSourceProperty

    Identifies the ItemsSource bindable property.

    Declaration
    public static readonly BindableProperty ItemsSourceProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    This bindable property is read-only.

    ItemTemplateContextTypeProperty

    Identifies the ItemTemplateContextType bindable property.

    Declaration
    public static readonly BindableProperty ItemTemplateContextTypeProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    This bindable property is read-only.

    ItemTemplateProperty

    Identifies the ItemTemplate bindable property.

    Declaration
    public static readonly BindableProperty ItemTemplateProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    This bindable property is read-only.

    LoadOnDemandCommandProperty

    Identifies the LoadOnDemandCommand bindable property.

    Declaration
    public static readonly BindableProperty LoadOnDemandCommandProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    This bindable property is read-only.

    LongPressCommandProperty

    Identifies the LongPressCommand bindable property.

    Declaration
    public static readonly BindableProperty LongPressCommandProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    This bindable property is read-only.

    NodePopulationModeProperty

    Identifies the NodePopulationMode bindable property.

    Declaration
    public static readonly BindableProperty NodePopulationModeProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    This bindable property is read-only.

    NodeSizeModeProperty

    Identifies the NodeSizeMode bindable property.

    Declaration
    public static readonly BindableProperty NodeSizeModeProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    This bindable property is read-only.

    NodesProperty

    Identifies the Nodes bindable property.

    Declaration
    public static readonly BindableProperty NodesProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    This bindable property is read-only.

    NotificationSubscriptionModeProperty

    Identifies the NotificationSubscriptionMode bindable property.

    Declaration
    public static readonly BindableProperty NotificationSubscriptionModeProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    This bindable property is read-only.

    RightTapCommandProperty

    Identifies the RightTapCommand bindable property.

    Declaration
    public static readonly BindableProperty RightTapCommandProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    This bindable property is read-only.

    ScrollBarVisibilityProperty

    Identifies the ScrollBarVisibility bindable property.

    Declaration
    public static readonly BindableProperty ScrollBarVisibilityProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    This bindable property is read-only.

    SelectedItemProperty

    Identifies the SelectedItem bindable property.

    Declaration
    public static readonly BindableProperty SelectedItemProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    This bindable property is read-only.

    SelectedItemsProperty

    Identifies the SelectedItems bindable property.

    Declaration
    public static readonly BindableProperty SelectedItemsProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    This bindable property is read-only.

    SelectionBackgroundProperty

    Identifies the SelectionBackground bindable property.

    Declaration
    public static readonly BindableProperty SelectionBackgroundProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    This bindable property is read-only.

    SelectionForegroundProperty

    Identifies the SelectionForeground bindable property.

    Declaration
    public static readonly BindableProperty SelectionForegroundProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    This bindable property is read-only.

    SelectionModeProperty

    Identifies the SelectionMode bindable property.

    Declaration
    public static readonly BindableProperty SelectionModeProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    This bindable property is read-only.

    TapCommandProperty

    Identifies the TapCommand bindable property.

    Declaration
    public static readonly BindableProperty TapCommandProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    This bindable property is read-only.

    Properties

    AutoExpandMode

    Gets or sets the value that determines how the nodes will be expanded when loading.

    Declaration
    public TreeViewAutoExpandMode AutoExpandMode { get; set; }
    Property Value
    Type Description
    TreeViewAutoExpandMode

    The default value is None.

    Examples
    SfTreeView treeView = new SfTreeView();
    treeView.AutoExpandMode = TreeViewAutoExpandMode.AllNodesExpanded;

    CheckBoxMode

    Gets or sets the value which indicates whether the CheckBoxMode is Individual or Recursive or None.

    Declaration
    public TreeNodeCheckBoxMode CheckBoxMode { get; set; }
    Property Value
    Type
    TreeNodeCheckBoxMode
    Remarks

    By default, it will be Nonei.e.,No update in any of the tree view node’s IsChecked property value.

    See Also
    CheckedItems
    GetCheckedNodes()
    ItemTemplateContextType

    CheckedItems

    Gets or sets list checked items list. Maintains list of data objects based on IsChecked.

    Declaration
    public ObservableCollection<object> CheckedItems { get; set; }
    Property Value
    Type
    System.Collections.ObjectModel.ObservableCollection<System.Object>
    Remarks

    This property maintains checked items only when you are binding ItemsSource to TreeView. To support recursive check programatically set CheckBoxMode as and NodePopulationMode as Instant. It does not support runtime changes in collection which is bind to CheckedItems.

    Examples
    SfTreeView treeView = new SfTreeView();
    ViewModel viewModel = new ViewModel();
    treeView.CheckedItems = viewModel.CheckedItems;
    //ViewModel
    public ObservableCollection<Folder> Folders { get; set; }
    private ObservableCollection<object> checkedItems;
    public ObservableCollection<object> CheckedItems
    {
    get
    {
        return checkedItems;
    }
    set
    {
        this.checkedItems = value;
        RaisedOnPropertyChanged("CheckedItems");
    }
    }
    public ViewModel()
    {
        this.Folders = GetFiles();
        checkedItems = new ObservableCollection<object>();
        checkedItems.Add(this.Folders[1]);
    }
    See Also
    GetCheckedNodes()
    CheckBoxMode
    ItemTemplateContextType

    ChildPropertyName

    Gets or sets the property name for the child object where ItemsSource is used to define the items for this SfTreeView.

    Declaration
    public string ChildPropertyName { get; set; }
    Property Value
    Type
    System.String
    Remarks

    Use the HierarchyPropertyDescriptor for different types in each level.

    Examples
    ViewModel viewModel = new ViewModel();
    SfTreeView treeView = new SfTreeView();
    treeView.ItemsSource = viewModel.ImageNodeInfo;
    treeView.ChildPropertyName = "SubFiles";
    See Also
    HierarchyPropertyDescriptors

    CollapseCommand

    Gets or sets the System.Windows.Input.ICommand that will be executed when the TreeViewNode is collapsed.

    Declaration
    public ICommand CollapseCommand { get; set; }
    Property Value
    Type
    System.Windows.Input.ICommand
    Examples
    SfTreeView treeview = new SfTreeView();
    treeview.CollapseCommand = viewModel.CollapsingCommand;
    
    public class CommandViewModel
    {
      private Command<Object> collapsingCommand;
    
      public Command<object> CollapsingCommand
      {
          get { return collapsingCommand; }
          set { collapsingCommand = value; }
      }
    
      public CommandViewModel()
      {
          CollapsingCommand = new Command<object>(CollapsingCommandMethod);
      }
    
      private void CollapsingCommandMethod(object obj)
      {
    
      }
    }

    CurrentItem

    Gets or sets the current selected item.

    Declaration
    public object CurrentItem { get; set; }
    Property Value
    Type Description
    System.Object

    The current item.

    Examples
    SfTreeView treeView = new SfTreeView();
    ViewModel viewModel = new ViewModel();
    treeView.ItemsSource = viewModel.Folders;
    treeView.CurrentItem = viewModel.Folders[0];
    See Also
    SelectionChanged
    SelectionChanging
    SelectionMode
    SelectedItem
    SelectedItems

    EnableHorizontalScrolling

    Gets or sets a value indicating whether horizontal scrolling is enabled for the SfTreeView.

    Declaration
    public bool EnableHorizontalScrolling { get; set; }
    Property Value
    Type
    System.Boolean

    ExpandActionTarget

    Gets or sets a value indicating whether node expand and collapse can only be performed in the expander view or in both the expander view and the content view.

    Declaration
    public TreeViewExpandActionTarget ExpandActionTarget { get; set; }
    Property Value
    Type
    TreeViewExpandActionTarget
    Remarks

    The default value is Expander.

    Examples
    SfTreeView treeView = new SfTreeView();
    treeView.ExpandActionTarget = TreeViewExpandActionTarget.Node;

    ExpandCommand

    Gets or sets the System.Windows.Input.ICommand the will be executed when the TreeViewNode is expanded.

    Declaration
    public ICommand ExpandCommand { get; set; }
    Property Value
    Type
    System.Windows.Input.ICommand
    Examples
    SfTreeView treeview = new SfTreeView();
    treeview.ExpandCommand = viewModel.ExpandingCommand;
    
    public class CommandViewModel
    {
      private Command<Object> expandingCommand;
    
      public Command<object> ExpandingCommand
      {
          get { return expandingCommand; }
          set { expandingCommand = value; }
      }
    
      public CommandViewModel()
      {
          ExpandingCommand = new Command<object>(ExpandingCommandMethod);
      }
    
      private void ExpandingCommandMethod(object obj)
      {
    
      }
    }

    ExpanderPosition

    Gets or sets the expander position in the SfTreeView. The default value is Start.

    Declaration
    public TreeViewExpanderPosition ExpanderPosition { get; set; }
    Property Value
    Type
    TreeViewExpanderPosition

    ExpanderTemplate

    Gets or sets the data template for the ExpanderView of TreeViewItem.

    Declaration
    public DataTemplate ExpanderTemplate { get; set; }
    Property Value
    Type
    Microsoft.Maui.Controls.DataTemplate
    Examples
    ViewModel viewModel = new ViewModel();
    SfTreeView treeView = new SfTreeView();
    

    treeView.ExpanderTemplate = new DataTemplate(() => { Image expanderImage = new Image(); expanderImage.SetBinding(Label.SourceProperty, "ExpanderIcon");

    return expanderImage; });

    See Also
    ItemTemplate
    ExpanderWidth
    ExpanderPosition

    ExpanderWidth

    Gets or sets the width of the expander in TreeViewItem.

    Declaration
    public double ExpanderWidth { get; set; }
    Property Value
    Type Description
    System.Double

    The default value is 32.

    See Also
    Indentation

    FullRowSelect

    Gets or sets a value indicating whether or not the selection spans the width of the tree view control.

    Declaration
    public bool FullRowSelect { get; set; }
    Property Value
    Type
    System.Boolean
    Remarks

    The default value is false, and the selection starts at the indent level only.

    HierarchyPropertyDescriptors

    Gets or sets the list of HierarchyPropertyDescriptors that holds a list of HierarchyPropertyDescriptor that offer type and property name information. TreeView generates child nodes based on ChildPropertyName if the type of data item matches TargetType.

    Declaration
    public HierarchyPropertyDescriptors HierarchyPropertyDescriptors { get; set; }
    Property Value
    Type
    HierarchyPropertyDescriptors
    Examples

    This example demonstrates how to set HierarchyPropertyDescriptors in XAML.

    <syncfusion:SfTreeView x:Name="treeView"
                           ItemsSource="{Binding Folders}">
               <syncfusion:SfTreeView.HierarchyPropertyDescriptors>
                   <treeviewengine:HierarchyPropertyDescriptor ChildPropertyName = "Files"
                                                               TargetType="local:Folder"/>
                   <treeviewengine:HierarchyPropertyDescriptor ChildPropertyName = "SubFiles"
                                                               TargetType="local:File"/>
               </syncfusion:SfTreeView.HierarchyPropertyDescriptors>
    </syncfusion:SfTreeView>
    See Also
    HierarchyPropertyDescriptor

    Indentation

    Gets or sets the distance to indent each child of a tree view item in SfTreeView.

    Declaration
    public double Indentation { get; set; }
    Property Value
    Type Description
    System.Double

    The default value is 30.

    See Also
    ExpanderWidth

    IsAnimationEnabled

    Gets or sets a value indicating whether expand/collapse animation is enabled.

    Declaration
    public bool IsAnimationEnabled { get; set; }
    Property Value
    Type
    System.Boolean

    ItemHeight

    Gets or sets the height of each TreeViewItem in SfTreeView.

    Declaration
    public double ItemHeight { get; set; }
    Property Value
    Type Description
    System.Double

    The default value is 48.

    See Also
    QueryNodeSize

    ItemsSource

    Gets or sets the source items for the template and displays them in the see cref="SfTreeView"/>.

    Declaration
    public object ItemsSource { get; set; }
    Property Value
    Type
    System.Object
    Examples
    ViewModel viewModel = new ViewModel();
    SfTreeView treeView = new SfTreeView();
    treeView.ItemsSource = viewModel.ImageNodeInfo;
    See Also
    ItemTemplate
    ChildPropertyName
    NodePopulationMode

    ItemTemplate

    Gets or sets the data template for the ContentView of TreeViewItem.

    Declaration
    public DataTemplate ItemTemplate { get; set; }
    Property Value
    Type
    Microsoft.Maui.Controls.DataTemplate
    Examples
    ViewModel viewModel = new ViewModel();
    SfTreeView treeView = new SfTreeView();
    

    treeView.ItemTemplate = new DataTemplate(() => { Label fileNameLabel = new Label() { FontSize = 18}; fileNameLabel.SetBinding(Label.TextProperty, "FileName");

    return new ViewCell { View = new StackLayout { Children = { fileNameLabel, } } }; });

    See Also
    ExpanderTemplate

    ItemTemplateContextType

    Gets or sets the binding context type for treeview items.

    Declaration
    public ItemTemplateContextType ItemTemplateContextType { get; set; }
    Property Value
    Type
    ItemTemplateContextType
    Remarks

    The default value is Item i.e., data model object. This property is only applicable in Bound mode. TreeViewNode will be the binding context for each treeview item in Unbound mode.

    LoadOnDemandCommand

    Gets or sets the System.Windows.Input.ICommand which will be executed when tap on the expander.

    Declaration
    public ICommand LoadOnDemandCommand { get; set; }
    Property Value
    Type
    System.Windows.Input.ICommand
    Remarks

    It is applicable for bound mode only. Return true in CanExecute method of this command to enable expander icon and also to execute on demand loading for that node, else return false.

    LongPressCommand

    Gets or sets the System.Windows.Input.ICommand that will be executed when the TreeViewItem is long pressed.

    Declaration
    public ICommand LongPressCommand { get; set; }
    Property Value
    Type
    System.Windows.Input.ICommand
    Examples
    SfTreeView treeview = new SfTreeView();
    treeview.LongPressCommand = viewModel.LongPressingCommand;
    public class CommandViewModel
    {
      private Command<Object> LongPressingCommand;
    
      public Command<object> LongPressingCommand
      {
          get { return LongPressingCommand; }
          set { LongPressingCommand = value; }
      }
    
      public CommandViewModel()
      {
          LongPressingCommand = new Command<object>(LongPressingCommand);
      }
    
      private void LongPressingCommandMethod(object obj)
      {
    
      }
    }

    NodePopulationMode

    Gets or sets the value indicating whether or not the child nodes should be populated when the treeview is loaded or just when the node is expanded.

    Declaration
    public TreeNodePopulationMode NodePopulationMode { get; set; }
    Property Value
    Type
    TreeNodePopulationMode
    Remarks

    When the NodePopulationMode is set to OnDemand, the child nodes will be populated only when the parent nodes are expanded. When the NodePopulationMode is set to Instant, all nodes will be populated when the SfTreeView is first loaded. The default value is OnDemand. This property is only applicable in Bound mode.

    Examples
    SfTreeView treeView = new SfTreeView();
    treeView.NodePopulationMode = TreeNodePopulationMode.Instant;

    Nodes

    Gets or sets the collection of tree view nodes assigned to the tree view control in Unbound mode.

    Declaration
    public TreeViewNodeCollection Nodes { get; set; }
    Property Value
    Type
    TreeViewNodeCollection
    Examples

    This example demonstrates how to set Nodes in XAML.

    <Syncfusion:SfTreeView x:Name="treeView">
        <Syncfusion:SfTreeView.Nodes>
            <Engine:TreeViewNode Content = "Grains" IsExpanded="True">
                <Engine:TreeViewNode.ChildNodes>
                    <Engine:TreeViewNode Content = "Cereals" IsExpanded="True">
                        <Engine:TreeViewNode.ChildNodes>
                            <Engine:TreeViewNode Content = "Rice"/>
                            <Engine:TreeViewNode Content = "Barley"/>
                        </Engine:TreeViewNode.ChildNodes>
                    </Engine:TreeViewNode>
                    <Engine:TreeViewNode Content = "Oilseeds">
                        <Engine:TreeViewNode.ChildNodes>
                            <Engine:TreeViewNode Content = "Safflower"/>
                        </Engine:TreeViewNode.ChildNodes>
                    </Engine:TreeViewNode>
                </Engine:TreeViewNode.ChildNodes>
            </Engine:TreeViewNode>
        </Syncfusion:SfTreeView.Nodes>
    </Syncfusion:SfTreeView>

    NodeSizeMode

    Gets or sets the TreeViewNodeSizeMode determining how the nodes adjust their size in SfTreeView.

    Declaration
    public TreeViewNodeSizeMode NodeSizeMode { get; set; }
    Property Value
    Type Description
    TreeViewNodeSizeMode

    The default value is None.

    Remarks

    Dynamic Nodes adjust their size dynamically based on content. None Nodes maintain the default item size.

    NotificationSubscriptionMode

    Gets or sets the value indicating whether to subscribe to collection and property changes of a data object in order to perform realtime data updates. When TreeView is bound to ItemsSource, it subscribes to collection and property changes of data objects based on NotificationSubscriptionMode.

    Declaration
    public TreeViewNotificationSubscriptionMode NotificationSubscriptionMode { get; set; }
    Property Value
    Type
    TreeViewNotificationSubscriptionMode
    Remarks

    When the NotificationSubscriptionMode is CollectionChange, TreeView's tree structure is updated when the collection of child objects changes. When the NotificationSubscriptionMode is PropertyChange, TreeView updates its ChildItems whenever the related collection property changes. The default value is None.

    Examples
    SfTreeView treeView = new SfTreeView();
    treeView.NotificationSubscriptionMode = TreeViewNotificationSubscriptionMode.CollectionChange | TreeViewNotificationSubscriptionMode.PropertyChange;

    RightTapCommand

    Gets or sets the System.Windows.Input.ICommand that will be executed when the TreeViewItem is tapped.

    Declaration
    public ICommand RightTapCommand { get; set; }
    Property Value
    Type
    System.Windows.Input.ICommand

    ScrollBarVisibility

    Gets or sets a value indicating whether or not the scrollbar should be displayed.

    Declaration
    public ScrollBarVisibility ScrollBarVisibility { get; set; }
    Property Value
    Type
    Microsoft.Maui.ScrollBarVisibility

    SelectedItem

    Gets or sets the first selected item.

    Declaration
    public object SelectedItem { get; set; }
    Property Value
    Type Description
    System.Object

    The selected item.

    Examples
    SfTreeView treeView = new SfTreeView();
    ViewModel viewModel = new ViewModel();
    treeView.ItemsSource = viewModel.Folders;
    treeView.SelectedItem = viewModel.Folders[0];
    See Also
    SelectionChanged
    SelectionChanging
    SelectionMode
    SelectedItems
    CurrentItem

    SelectedItems

    Gets or sets the selected items for selection.

    Declaration
    public ObservableCollection<object> SelectedItems { get; set; }
    Property Value
    Type Description
    System.Collections.ObjectModel.ObservableCollection<System.Object>

    The collection of object that contains data item that are selected.

    Examples
    SfTreeView treeView = new SfTreeView();
    ViewModel viewModel = new ViewModel();
    treeView.ItemsSource = viewModel.Folders;
    treeView.SelectionMode = SelectionMode.Multiple;
    treeView.SelectedItems = viewModel.SelectedItems;
    
    //ViewModel
    public ObservableCollection<object> Folders{ get; set; }
    private ObservableCollection<object> selectedItems;
    public ObservableCollection<object> SelectedItems
    {
        get
        {
            return selectedItems;
        }
        set
        {
                selectedItems = value;
            }
        }
    
    public ViewModel()
    {
        this.Folders = GenerateItemsSource();
        this.SelectedItems = new ObservableCollection<object>();
        this.SelectedItems.Add(this.Folders[1]);
        this.SelectedItems.Add(this.Folders[2]);
        this.SelectedItems.Add(this.Folders[3]);
    }
    See Also
    SelectionChanged
    SelectionChanging
    SelectionMode
    SelectedItem

    SelectionBackground

    Gets or sets the background colour of the selection for the selected item.

    Declaration
    public Brush SelectionBackground { get; set; }
    Property Value
    Type
    Microsoft.Maui.Controls.Brush
    Examples
    SfTreeView treeView = new SfTreeView();
    treeView.SelectionBackground = Brush.Green;
    See Also
    SelectionChanged
    SelectionChanging
    SelectionMode
    SelectedItem
    CurrentItem
    SelectedItems
    SelectionForeground

    SelectionForeground

    Gets or sets the selected item foreground color.

    Declaration
    public Color SelectionForeground { get; set; }
    Property Value
    Type
    Microsoft.Maui.Graphics.Color
    Remarks

    It will applicable for unbound mode only.

    See Also
    SelectionChanged
    SelectionChanging
    SelectionMode
    SelectedItem
    CurrentItem
    SelectedItems
    SelectionForeground

    SelectionMode

    Gets or sets the selection mode for selection.

    Declaration
    public TreeViewSelectionMode SelectionMode { get; set; }
    Property Value
    Type
    TreeViewSelectionMode
    Remarks

    The default value is Single.

    Examples
    SfTreeView treeView = new SfTreeView();
    treeView.SelectionMode = TreeViewSelectionMode.SingleDeselect;
    See Also
    SelectionChanged
    SelectionChanging

    TapCommand

    Gets or sets the System.Windows.Input.ICommand that will be executed when the TreeViewItem is tapped.

    Declaration
    public ICommand TapCommand { get; set; }
    Property Value
    Type
    System.Windows.Input.ICommand
    Examples
    SfTreeView treeview = new SfTreeView();
    treeview.TapCommand = viewModel.TappedCommand;
    
    public class CommandViewModel
    {
      private Command<Object> tappedCommand;
    
      public Command<object> TappedCommand
      {
          get { return tappedCommand; }
          set { tappedCommand = value; }
      }
    
      public CommandViewModel()
      {
          TappedCommand = new Command<object>(TappedCommandMethod);
      }
    
      private void TappedCommandMethod(object obj)
      {
    
      }
    }

    Methods

    ArrangeContent(Rect)

    This method is called during the measure pass of a layout cycle to arrange the elements.

    Declaration
    protected override Size ArrangeContent(Rect bounds)
    Parameters
    Type Name Description
    Microsoft.Maui.Graphics.Rect bounds

    Indicates the bounds value of the element.

    Returns
    Type Description
    Microsoft.Maui.Graphics.Size

    A Microsoft.Maui.Graphics.Size which contains the desired size of the element.

    Overrides
    SfView.ArrangeContent(Rect)

    BringIntoView(TreeViewNode, Boolean, Boolean, ScrollToPosition)

    Attempts to bring the tree view item into view by scrolling.

    Declaration
    public void BringIntoView(TreeViewNode node, bool disableAnimation = false, bool canExpand = false, ScrollToPosition scrollToPosition)
    Parameters
    Type Name Description
    TreeViewNode node

    Represents the TreeViewNode to be scrolled.

    System.Boolean disableAnimation

    True to disable scroll animation while changing views; false otherwise. The default is false.

    System.Boolean canExpand

    True to expand the collapsed nodes and bring the collapsed node into view; false otherwise. The default is false.

    Microsoft.Maui.Controls.ScrollToPosition scrollToPosition

    Specifies the position in the view to which the object is scrolled.

    Remarks

    When executing this method with the 'canExpand' parameter set to true, the NodePopulationMode property must be set to to populate all nodes and bring the collapsed node into view.

    BringIntoView(Object, Boolean, Boolean, ScrollToPosition)

    Attempts to bring the tree view item into view by scrolling.

    Declaration
    public void BringIntoView(object dataObject, bool disableAnimation = false, bool canExpand = false, ScrollToPosition scrollToPosition)
    Parameters
    Type Name Description
    System.Object dataObject

    Represents the data object associated with the TreeViewNode to be scrolled.

    System.Boolean disableAnimation

    True to disable scroll animation while changing views; false otherwise. The default is false.

    System.Boolean canExpand

    True to expand the collapsed nodes and bring the collapsed node into view; false otherwise. The default is false.

    Microsoft.Maui.Controls.ScrollToPosition scrollToPosition

    Specifies the position in the view to which the object is scrolled.

    Remarks

    When executing this method with the 'canExpand' parameter set to true, the NodePopulationMode property must be set to to populate all nodes and bring the collapsed node into view.

    CollapseAll()

    Collapses all the nodes in the SfTreeView.

    Declaration
    public void CollapseAll()

    CollapseNode(TreeViewNode)

    Collapses the specified TreeViewNode.

    Declaration
    public void CollapseNode(TreeViewNode item)
    Parameters
    Type Name Description
    TreeViewNode item

    Specifies the TreeViewNode to be collapses from the view.

    CollapseNodes(Int32)

    Collapses all the tree view items based on the specified level.

    Declaration
    public void CollapseNodes(int level = -1)
    Parameters
    Type Name Description
    System.Int32 level

    Specifies the level of TreeViewNode to collapse all TreeViewItems from the view.

    ExpandAll()

    Expands all the nodes in the SfTreeView.

    Declaration
    public void ExpandAll()

    ExpandNode(TreeViewNode)

    Expands the specified TreeViewNode.

    Declaration
    public void ExpandNode(TreeViewNode item)
    Parameters
    Type Name Description
    TreeViewNode item

    Specifies the TreeViewNode to expand it in the view.

    ExpandNodes(Int32)

    Expands all the tree view items based on the specified level.

    Declaration
    public void ExpandNodes(int level = -1)
    Parameters
    Type Name Description
    System.Int32 level

    Specifies the level of TreeViewNode to expand all TreeViewItems in the view.

    GetCheckedNodes()

    Get the all checked nodes in the SfTreeView. When binding ItemsSource, you can get the checked items list using CheckedItems.

    Declaration
    public ObservableCollection<TreeViewNode> GetCheckedNodes()
    Returns
    Type Description
    System.Collections.ObjectModel.ObservableCollection<TreeViewNode>

    Returns the collection of checked nodes.

    See Also
    CheckedItems
    CheckBoxMode
    ItemTemplateContextType

    MeasureContent(Double, Double)

    This method is called during the measure pass of a layout cycle to get the desired size of an element.

    Declaration
    protected override Size MeasureContent(double widthConstraint, double heightConstraint)
    Parameters
    Type Name Description
    System.Double widthConstraint

    The available width for the element to use.

    System.Double heightConstraint

    The available height for the element to use.

    Returns
    Type Description
    Microsoft.Maui.Graphics.Size

    A Microsoft.Maui.SizeRequest which contains the desired size of the element.

    Overrides
    SfView.MeasureContent(Double, Double)
    Remarks

    The results of this method will be (-1, -1) if the element has not yet been realized with a platform specific backing control. Overriding this method does not require a call to the base class so long as a valid SizeRequest is returned.

    OnPropertyChanged(String)

    Need to handle the run time changes of System.ComponentModel.PropertyChangedEventArgs of SfTreeView.

    Declaration
    protected override void OnPropertyChanged(string propertyName = null)
    Parameters
    Type Name Description
    System.String propertyName

    Represents the property changed event arguments.

    RefreshView(Boolean)

    Refresh the TreeViewItem in the UI.

    Declaration
    public void RefreshView(bool canResetNodeView = false)
    Parameters
    Type Name Description
    System.Boolean canResetNodeView

    Indicates that the tree node views should be reset.

    ResetTreeViewItems(Object)

    Method for resetting the visible treeview items. If the parameter is null, the visible treeview items will be reset; otherwise, the specific treeview item will be reset.

    Declaration
    public void ResetTreeViewItems(object dataObject = null)
    Parameters
    Type Name Description
    System.Object dataObject

    Represents the TreeViewNode in Unbound mode, and the data object associated with TreeViewNode in Bound mode.

    SelectAll()

    Selects all the items in the SfTreeView.

    Declaration
    public void SelectAll()

    Events

    ItemDoubleTapped

    Occurs when the TreeViewItem's ContentView is double tapped.

    Declaration
    public event EventHandler<ItemDoubleTappedEventArgs> ItemDoubleTapped
    Event Type
    Type
    System.EventHandler<ItemDoubleTappedEventArgs>
    Examples

    The following example demonstrates how to wire a double tapped event in SfTreeView.

    treeView.ItemDoubleTapped += TreeView_ItemDoubleTapped;
    

    private void TreeView_ItemDoubleTapped(object sender, ItemDoubleTappedEventArgs e) { viewModel.ImageNodeInfo.Remove(e.Node.Content as FileManager); }

    See Also
    ItemTapped
    ItemLongPress

    ItemLongPress

    Occurs when the TreeViewItem's ContentView is long pressed.

    Declaration
    public event EventHandler<ItemLongPressEventArgs> ItemLongPress
    Event Type
    Type
    System.EventHandler<ItemLongPressEventArgs>
    Examples

    The following example demonstrates how to wire a long press event in SfTreeView.

    treeView.ItemLongPress += TreeView_ItemLongPress;
    

    private void TreeView_ItemLongPress(object sender, ItemLongPressEventArgs e) { viewModel.ImageNodeInfo.Remove(e.Node.Content as FileManager); }

    See Also
    ItemTapped
    ItemDoubleTapped

    ItemRightTapped

    Occurs when the TreeViewItem's ContentView is right tapped.

    Declaration
    public event EventHandler<ItemRightTappedEventArgs> ItemRightTapped
    Event Type
    Type
    System.EventHandler<ItemRightTappedEventArgs>

    ItemTapped

    Occurs when the TreeViewItem's ContentView is tapped.

    Declaration
    public event EventHandler<ItemTappedEventArgs> ItemTapped
    Event Type
    Type
    System.EventHandler<ItemTappedEventArgs>
    Examples

    The following example demonstrates how to wire a tapped event in SfTreeView.

    treeView.ItemTapped += TreeView_ItemTapped;
    

    private void TreeView_ItemTapped(object sender, ItemTappedEventArgs e) { viewModel.ImageNodeInfo.Remove(e.Node.Content as FileManager); }

    See Also
    ItemDoubleTapped
    ItemLongPress

    KeyDown

    Occurs when key is pressed while SfTreeView has focus.

    Declaration
    public event EventHandler<KeyPressEventArgs> KeyDown
    Event Type
    Type
    System.EventHandler<KeyPressEventArgs>

    Loaded

    Occurs when the SfTreeView is loaded for the first time.

    Declaration
    public event EventHandler<TreeViewLoadedEventArgs> Loaded
    Event Type
    Type
    System.EventHandler<TreeViewLoadedEventArgs>
    Remarks

    Any properties set within this event callback will result in an additional refresh call when the SfTreeView is loaded.

    Examples
    treeView.Loaded += TreeView_Loaded;
    private void TreeView_Loaded(object sender, TreeViewLoadedEventArgs e)
    {
        treView.SelectedItems.Add(viewModel.ImageNodeInfo[2]);
    }

    NodeChecked

    Occurs when an IsChecked is being changed.

    Declaration
    public event EventHandler<NodeCheckedEventArgs> NodeChecked
    Event Type
    Type
    System.EventHandler<NodeCheckedEventArgs>
    Examples

    The following example demonstrates how to wire a NodeChecked event in SfTreeView.

    treeView.NodeChecked += treeView_NodeChecked;
    

    private void treeView_NodeChecked(object sender, Syncfusion.Maui.TreeView.NodeCheckedEventArgs e) { var checkeditems = treeView.GetCheckedNodes(); foreach (var item in checkeditems) { System.Diagnostics.Debug.WriteLine(item.Content); } }

    NodeCollapsed

    Occurs when a TreeViewNode is collapsed.

    Declaration
    public event EventHandler<NodeExpandedCollapsedEventArgs> NodeCollapsed
    Event Type
    Type
    System.EventHandler<NodeExpandedCollapsedEventArgs>
    Remarks

    This event occurs after the NodeCollapsing event if that event is not canceled.

    Examples

    The following example demonstrates how to wire the node expanded event in SfTreeView.

    treeView.NodeCollapsed += TreeView_NodeCollapsed;
    

    private void TreeView_NodeCollapsed(object sender, NodeExpandedCollapsedEventArgs e) { // Do required actions here. }

    See Also
    NodeCollapsing
    NodeExpanding
    NodeExpanded

    NodeCollapsing

    Occurs when a TreeViewNode is being collapsed.

    Declaration
    public event EventHandler<NodeExpandingCollapsingEventArgs> NodeCollapsing
    Event Type
    Type
    System.EventHandler<NodeExpandingCollapsingEventArgs>
    Remarks

    The NodeCollapsing event is a cancelable event and can be cancelled by handling the event and setting the Cancel property to true. If the event is cancelled, the node collapse process for the tapped TreeViewNode is also cancelled. We can also customise the node that is being collapsed using the NodeExpandingCollapsingEventArgs event argument.

    Examples

    The following example demonstrates how to wire the node collapsing event in SfTreeView.

    treeView.NodeCollapsing += TreeView_NodeCollapsing;
    

    private void TreeView_NodeCollapsing(object sender, NodeExpandingCollapsingEventArgs e) { if(e.Node.Level == 0) { e.Cancel = true; } }

    See Also
    NodeCollapsed
    NodeExpanding
    NodeExpanded

    NodeExpanded

    Occurs when a TreeViewNode is expanded.

    Declaration
    public event EventHandler<NodeExpandedCollapsedEventArgs> NodeExpanded
    Event Type
    Type
    System.EventHandler<NodeExpandedCollapsedEventArgs>
    Remarks

    This event occurs after the NodeExpanding event if that event is not canceled.

    Examples

    The following example demonstrates how to wire the node expanded event in SfTreeView.

    treeView.NodeExpanded += TreeView_NodeExpanded;
    

    private void TreeView_NodeExpanded(object sender, NodeExpandedCollapsedEventArgs e) { // Do required actions here. }

    See Also
    NodeExpanding
    NodeCollapsing
    NodeCollapsed

    NodeExpanding

    Occurs when a TreeViewNode is being expanded.

    Declaration
    public event EventHandler<NodeExpandingCollapsingEventArgs> NodeExpanding
    Event Type
    Type
    System.EventHandler<NodeExpandingCollapsingEventArgs>
    Remarks

    The NodeExpanding event is a cancelable event and can be cancelled by handling the event and setting the Cancel property to true. If the event is cancelled, the node expand process for the tapped TreeViewNode is also cancelled. We can also customise the node that is being expanded using the NodeExpandingCollapsingEventArgs event argument.

    Examples

    The following example demonstrates how to wire the node expanding event in SfTreeView.

    treeView.NodeExpanding += TreeView_NodeExpanding;
    

    private void TreeView_NodeExpanding(object sender, NodeExpandingCollapsingEventArgs e) { if(e.Node.Level == 0) { e.Cancel = true; } }

    See Also
    NodeExpanded
    NodeCollapsing
    NodeCollapsed

    QueryNodeSize

    Occurs whenever an item comes into view and queries the item size.

    Declaration
    public event EventHandler<QueryNodeSizeEventArgs> QueryNodeSize
    Event Type
    Type
    System.EventHandler<QueryNodeSizeEventArgs>
    Remarks

    By handling the QueryNodeSize event, we can determine whether the specified size should be applied to the item or not. When the Handled property within the QueryNodeSizeEventArgs argument is set to false, the designated size will not be assigned to the item.

    Examples

    The following example demonstrates how to wire a QueryNodeSize event in SfTreeView.

    treeView.QueryNodeSize += TreeView_QueryNodeSize;
    

    private void TreeView_QueryNodeSize(object sender, QueryNodeSizeEventArgs e) { e.Height = e.GetActualNodeHeight(); e.Handled = true; }

    See Also
    ItemHeight

    SelectionChanged

    Occurs once the selection process for the selected item in the SfTreeView has been completed.

    Declaration
    public event EventHandler<ItemSelectionChangedEventArgs> SelectionChanged
    Event Type
    Type
    System.EventHandler<ItemSelectionChangedEventArgs>
    Examples

    The following example demonstrates how to wire the selection changed event in SfTreeView.

    treeView.SelectionChanged += TreeView_SelectionChanged;
    

    private void TreeView_SelectionChanged(object sender, ItemSelectionChangedEventArgs e) { // Do required actions here. }

    See Also
    SelectionChanging

    SelectionChanging

    Occurs while selecting a TreeViewItem's contentview at the execution time.

    Declaration
    public event EventHandler<ItemSelectionChangingEventArgs> SelectionChanging
    Event Type
    Type
    System.EventHandler<ItemSelectionChangingEventArgs>
    Remarks

    The SelectionChanging event is a cancelable event and can be cancelled by handling the event and setting the Cancel property to true. If the event is cancelled, the selection process for the selected TreeViewItem's contentview is cancelled.

    Examples

    The following example demonstrates how to wire the selection changing event in SfTreeView.

    treeView.ItemsSource = viewModel.ImageNodeInfo;
    treeView.SelectionChanging += TreeView_SelectionChanging;
    

    private void TreeView_SelectionChanging(object sender, ItemSelectionChangingEventArgs e) { if (e.AddedItems[0] == viewModel.ImageNodeInfo[0]) { e.Cancel = true; } }

    See Also
    SelectionChanged

    Implements

    IDrawableLayout
    Microsoft.Maui.Graphics.IDrawable
    Microsoft.Maui.IAbsoluteLayout
    Microsoft.Maui.ILayout
    Microsoft.Maui.IView
    Microsoft.Maui.IElement
    Microsoft.Maui.ITransform
    Microsoft.Maui.IContainer
    System.Collections.Generic.IList<>
    System.Collections.Generic.ICollection<>
    System.Collections.Generic.IEnumerable<>
    System.Collections.IEnumerable
    Microsoft.Maui.ISafeAreaView
    Microsoft.Maui.IPadding
    Microsoft.Maui.ICrossPlatformLayout
    Microsoft.Maui.IVisualTreeElement
    Back to top Generated by DocFX
    OSZAR »
    Copyright © 2001 - 2025 Syncfusion Inc. All Rights Reserved
    OSZAR »