Hi,
Given a RadTreeViewItem, I want to expand all if it's descendants. I receive the first RadTreeViewItem via an attached behavior:
private void OnLoaded(object sender, RoutedEventArgs e) { RadTreeViewItem tvi = AssociatedObject;
after doing some checks I call tvi.IsExpanded = True and tvi.IsSelected = True;
This gets my tree opened up to the desired node. Now I want to expand all of it's children so the user doesn't have to open up each branch by hand.
01.private void ExpandChildren(RadTreeViewItem tvItem)02.{03. 04. //var container = tvItem.ItemContainerGenerator.IndexFromContainer();05. var tvi = tvItem;06. foreach (RadTreeViewItem item in tvi.Items)07. {08. var kid = tvi.ParentTreeView.ContainerFromItemRecursive(item);09. kid.IsExpanded = true;10. if (kid.HasItems)11. ExpandChildren(kid);12. }13.}
However, this function blows up on line 6 complaining that the item cannot be converted from the value (in my case an app specific class) type to a RadTreeViewItem. I tried using ContainerFromItemRecursive, but it always seems to return null. How to convert a tvi.Items[n] to a RadTreeViewItem that I can mark IsExpanded = true?
This seems like this shouldn't be that hard.
Can someone please point me in the right direction?
Thanks ... Ed
