I have a scenario where I have a tree view control to which I am providing ItemSource from code behind and my collection for Item source comes from a service asynchrously.
I have almost 10 root elements added to this treeview and each root level element has two more levels.
What I want to do is that I only want to expand root elements but not their children e.g.
I tried following code, but didn't work. It returns me null item:
if (_radTree != null && _Top != null)
_radTree.ItemsSource = _Top;
foreach (var item in _radTree.Items)
TreeViewItem tviItem = _radTree.ItemContainerGenerator.ContainerFromItem(item) as TreeViewItem;
tviItem.IsExpanded = true;
_radTree.ItemContainerGenerator.ContainerFromItem(item) returns null I have tried ContainerFromIndex(index) as well, which also returns true.
I can not use this function in TreeView's Loaded event because, tree is empty at the time of load since my ItemSource is comming from webservice.
I have noticed there is another function but couldn't manage to use it, which is "ExpandItemByPath"
Is there any solution to my problem?
Thanks in Advance