Setting node.IsExpanded to true only works at the top level of the hierarchy

I am developing an Android app that uses SfTreeView.

I am trying to save the expanded status of items in a tree so that the app can be restarted and the tree would reflect the last saved state of expanded nodes.

The tree source database is updated properly, and on restarting the app the data is loaded into the tree, but only the first tree item that shold be expanded is doing it, and any child noded that should also be expanded are not.

Looking at the data in debug, it seems that setting IsExpanded on a node to true clears the child nodes IsExpanded status, even though the source items have their ChildProperty that indicates they have childen properly set.

To show the poblem, compile and start the app in the Zip file.

The app opens showing only one node.

Expand the node, then expand the first child node.

Toch on the hamburger menu and touch the only enty, his will save the expansion status to the app database.

Close the app, then restart it. The app opens showing the top node and its first level children, but all of the childen now show that they have no nodes although the source still has its children.


Attachment: Things_958f3d94.zip

1 Reply

AF Anees Fathima Shajahan Syncfusion Team March 17, 2025 01:19 PM UTC

Hi Paul,


We reviewed your sample and found that the ExpandNodes method is being called from the constructor, where the IsExpanded property is set to true to maintain the expanded state. However, when set in the constructor, the TreeView is not fully loaded, preventing child nodes from being displayed.

As a workaround, we recommend setting IsExpanded to true by calling the ExpandNodes method within the TreeView's loaded event. We have attached the modified sample for your reference.

 

MainPage.xaml

 <sf:SfTreeView x:Name="Hierarchy" Loaded="Hierarchy_Loaded"

/>

 

MainPage.xaml.cs

private void Hierarchy_Loaded(object sender, Syncfusion.Maui.TreeView.TreeViewLoadedEventArgs e)

{

    if (Globals.Settings.Expansion == 0)

        Hierarchy.CollapseNode(Hierarchy.Nodes.First());

    else

        mainPage_Model.ExpandNodes(Hierarchy.Nodes.First());

}


Regards,

Anees Fathima.


Attachment: Things_bbba2ded.zip

Loader.
Up arrow icon