/// <summary> /// Removes items from the tree. /// </summary> /// <param name="context">The remove context.</param> /// <param name="item">The item from which to remove children.</param> protected virtual void RemoveChildren(IRemoveItemContext context, object item) { ExtendedTreeViewItemBase?ItemContainer = ContainerFromItem(item); if ((ItemContainer != null && ItemContainer.IsExpanded) || (ItemContainer == null && IsItemExpandedAtStart)) { IList Children = GetItemChildren(item); #if NETCOREAPP3_1 foreach (object?ChildItem in Children) { if (ChildItem != null) { RemoveChildren(context, ChildItem); } } #else foreach (object ChildItem in Children) { RemoveChildren(context, ChildItem); } #endif } if (context != null) { InternalRemove(context.ShownIndex, item); context.NextIndex(); } if (ExpandedChildren.ContainsKey(item)) { ExpandedChildren.Remove(item); } }
/// <summary> /// Called when children of an item have been removed. /// </summary> /// <param name="item">The item.</param> /// <param name="startIndex">Index of the first removed child.</param> /// <param name="itemList">The list of removed children.</param> protected virtual void OnItemRemoveChildren(object item, int startIndex, IList itemList) { NotifyPreviewCollectionModified(TreeViewCollectionOperation.Remove); if (IsExpanded(item)) { int ShownPreviousChildrenCount = VisibleChildren.IndexOf(item); ShownPreviousChildrenCount += CountPreviousChildrenExpanded(item, startIndex, -1); int ShownIndex = ShownPreviousChildrenCount; IRemoveItemContext Context = CreateRemoveItemContext(item, ShownIndex); Context.Start(); #if NETCOREAPP3_1 foreach (object?ChildItem in itemList) { if (ChildItem != null) { RemoveChildren(Context, ChildItem); } } #else foreach (object ChildItem in itemList) { RemoveChildren(Context, ChildItem); } #endif Context.Complete(); Context.Close(); } NotifyCollectionModified(TreeViewCollectionOperation.Remove); }
/// <summary> /// Called when children of an item are reset. /// </summary> /// <param name="item">The item.</param> protected virtual void OnItemResetChildren(object item) { NotifyPreviewCollectionModified(TreeViewCollectionOperation.Remove); if (IsExpanded(item)) { object?ParentItem = GetItemParent(item); int StartIndex; int RemoveCount; if (ParentItem != null) { StartIndex = VisibleChildren.IndexOf(item) + 1; IList Siblings = GetItemChildren(ParentItem); int ItemIndex = Siblings.IndexOf(item); if (ItemIndex + 1 < Siblings.Count) { object NextItem = Siblings[ItemIndex + 1] !; int EndIndex = VisibleChildren.IndexOf(NextItem); RemoveCount = EndIndex - StartIndex; } else { RemoveCount = CountVisibleChildren(item); } } else { StartIndex = 1; RemoveCount = VisibleChildren.Count - 1; } IRemoveItemContext Context = CreateRemoveItemContext(item, StartIndex); Context.Start(); for (int i = 0; i < RemoveCount; i++) { object RemovedItem = VisibleChildren[Context.ShownIndex]; InternalRemove(Context.ShownIndex, RemovedItem); Context.NextIndex(); if (ExpandedChildren.ContainsKey(RemovedItem)) { ExpandedChildren.Remove(RemovedItem); } } Context.Complete(); Context.Close(); } NotifyCollectionModified(TreeViewCollectionOperation.Remove); }
private void OnItemMoveChildrenPreviousAfter(object item, int oldIndex, int newIndex, IList itemList) { int ShownPreviousChildrenCount = VisibleChildren.IndexOf(item); int RemoveIndex = ShownPreviousChildrenCount; RemoveIndex += CountPreviousChildrenExpanded(item, oldIndex + 1, newIndex); IRemoveItemContext RemoveContext = CreateRemoveItemContext(item, RemoveIndex); RemoveContext.Start(); #if NETCOREAPP3_1 foreach (object?ChildItem in itemList) { if (ChildItem != null) { RemoveChildren(RemoveContext, ChildItem); } } #else foreach (object ChildItem in itemList) { RemoveChildren(RemoveContext, ChildItem); } #endif RemoveContext.Complete(); RemoveContext.Close(); int InsertIndex = ShownPreviousChildrenCount; InsertIndex += CountPreviousChildrenExpanded(item, newIndex, -1); IInsertItemContext InsertContext = CreateInsertItemContext(item, InsertIndex); InsertContext.Start(); #if NETCOREAPP3_1 foreach (object?ChildItem in itemList) { if (ChildItem != null) { InsertChildren(InsertContext, ChildItem, item); } } #else foreach (object ChildItem in itemList) { InsertChildren(InsertContext, ChildItem, item); } #endif InsertContext.Complete(); InsertContext.Close(); }