private void UnregisterItem(TreeViewItem item) { item.Expanded -= ExpandedChanged; item.Collapsed -= ExpandedChanged; foreach (var container in GetItems(item)) { UnregisterItem(container); } }
private static IEnumerable <TreeViewItem> GetItems(TreeViewItem parent) { var item = TreeViewElementFinder.GetFirstVirtualizedItem(parent); if (item == null) { yield break; } while (item != null) { yield return(item); item = (TreeViewItem)TreeViewElementFinder.FindNextSibling(item); } }
private static bool IsParentOfItem(TreeViewItem item, IEnumerable <TreeViewItem> parentCandidates) { foreach (var parent in parentCandidates) { var current = item.ParentTreeViewItem; while (current != null) { if (ReferenceEquals(current, parent)) { return(true); } current = current.ParentTreeViewItem; } } return(false); }
private TreeViewItem GetTreeViewItem(string propertyPath) { IEnumerable <TreeViewItem> currentPropertyCollection = GetItems(AssociatedObject); string[] members = propertyPath.Split('.'); TreeViewItem item = null; foreach (var member in members.Skip(0)) { item = currentPropertyCollection.FirstOrDefault(x => { var vm = x.DataContext as IChildViewModel; return(vm != null && GetName(vm) == member); }); if (item == null) { return(null); } currentPropertyCollection = GetItems(item); } return(item); }