Hi, I’m trying to expand all nodes in XamDataTree after ItemSource is set by ViewModel. ViewModel calls UpdateOnData() :
public void UpdateOnData()
{
SetNodeExpandedState (ReconRunsTree.Nodes, true);
}
private void SetNodeExpandedState (IEnumerable<XamDataTreeNode> nodes, bool expand)
foreach (XamDataTreeNode item in nodes) // ??? nodes collection is empty
item.IsExpanded = expand;
this.SetNodeExpandedState(item.Nodes, expand);
The problem is – Nodes collection is empty, even though ItemsSource is set properly. At which point after ItemsSource is set, the Nodes collection becomes populated ?
Hello Sergey,
Thank you for your post. I have been looking into it and I can say that in when the XamDataTree’s Loaded event is fired the Nodes collection is already populated, so you can use it in order to achieve your goal. Please let me know if this helps you or you need further assistance on this matter.
Looking forward for your reply.
Hi Stefan,
I my case, tree binding is set in xaml :
<ig:XamDataTree x:Name="ReconRunsTree" ItemsSource="{Binding ReconSchedule}" ... >
When Loaded event is fired, the ItemsSource property of the tree is bound to list, but the list is empty, because ViewModel is populating it asynchronously. While list is being populated, it fires CollectionChanged events.
I guess, the question is - does XamDataTree populate Nodes collection on CollectionChanged event ? Or I need to do something else to force Nodes populating after data is ready ?
I also noticed that selection (by clicking) of the root node in XamDataTree results in populating Nodes collection. Is there a way to select root node programmatically ?
If you want to expand all nodes whne they are loaded, you can handle XamDataTree's InitializaNode event, add the follwoing code in its handler:
e.Node.IsExpanded = true;
which will expand every initialized node.
Hope this helps you.
That works. Thank you
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.