private static void SetChildren(TreeViewItem item, List <TreeViewItem> newChildList) { if (!LazyTreeViewDataSource.IsChildListForACollapsedParent(item.children) || newChildList != null) { item.children = newChildList; } }
internal static HashSet <int> GetParentsBelowItem(TreeViewItem fromItem) { if (fromItem == null) { throw new ArgumentNullException("fromItem"); } Stack <TreeViewItem> stack = new Stack <TreeViewItem>(); stack.Push(fromItem); HashSet <int> hashSet = new HashSet <int>(); while (stack.Count > 0) { TreeViewItem treeViewItem = stack.Pop(); if (treeViewItem.hasChildren) { hashSet.Add(treeViewItem.id); if (LazyTreeViewDataSource.IsChildListForACollapsedParent(treeViewItem.children)) { throw new InvalidOperationException("Invalid tree for finding descendants: Ensure a complete tree when using this utillity method."); } foreach (TreeViewItem current in treeViewItem.children) { stack.Push(current); } } } return(hashSet); }
// Assumes full tree internal static void GetParentsBelowItem(TreeViewItem fromItem, HashSet <int> parentsBelow) { if (fromItem == null) { throw new ArgumentNullException("fromItem"); } Stack <TreeViewItem> stack = new Stack <TreeViewItem>(); stack.Push(fromItem); while (stack.Count > 0) { TreeViewItem current = stack.Pop(); if (current.hasChildren) { parentsBelow.Add(current.id); if (LazyTreeViewDataSource.IsChildListForACollapsedParent(current.children)) { throw new InvalidOperationException("Invalid tree for finding descendants: Ensure a complete tree when using this utillity method."); } foreach (var foo in current.children) { stack.Push(foo); } } } }
static void SetChildren(TreeViewItem item, List <TreeViewItem> newChildList) { // Do not touch children if we have a LazyParent and did not find any children == keep lazy children if (LazyTreeViewDataSource.IsChildListForACollapsedParent(item.children) && newChildList == null) { return; } item.children = newChildList; }
protected static bool IsChildListForACollapsedParent(IList <TreeViewItem> childList) { return(LazyTreeViewDataSource.IsChildListForACollapsedParent(childList)); }