Exemplo n.º 1
0
        /// <summary>
        /// Inserts children of an item.
        /// </summary>
        /// <param name="context">The insertion context.</param>
        /// <param name="item">The item with children.</param>
        /// <param name="parentItem">The parent item.</param>
        protected virtual void InsertChildren(IInsertItemContext context, object item, object?parentItem)
        {
            IList Children   = GetItemChildren(item);
            bool  IsExpanded = IsItemExpandedAtStart || (parentItem == null && IsRootAlwaysExpanded);

            if (IsExpanded)
            {
                ExpandedChildren.Add(item, Children);
            }

            InternalInsert(context.ShownIndex, item);
            context.NextIndex();

            if (IsExpanded)
            {
#if NETCOREAPP3_1
                foreach (object?ChildItem in Children)
                {
                    if (ChildItem != null)
                    {
                        InsertChildren(context, ChildItem, item);
                    }
                }
#else
                foreach (object ChildItem in Children)
                {
                    InsertChildren(context, ChildItem, item);
                }
#endif
            }
        }
        /// <summary>
        /// Called when children have been added to an item.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="startIndex">Index where the first child is added.</param>
        /// <param name="itemList">The list of children.</param>
        protected virtual void OnItemAddChildren(object item, int startIndex, IList itemList)
        {
            NotifyPreviewCollectionModified(TreeViewCollectionOperation.Insert);

            if (IsExpanded(item))
            {
                int ShownPreviousChildrenCount = VisibleChildren.IndexOf(item);
                ShownPreviousChildrenCount += CountPreviousChildrenExpanded(item, startIndex, -1);

                int ShownIndex = ShownPreviousChildrenCount;

                IInsertItemContext Context = CreateInsertItemContext(item, ShownIndex);
                Context.Start();

#if NETCOREAPP3_1
                foreach (object?ChildItem in itemList)
                {
                    if (ChildItem != null)
                    {
                        InsertChildren(Context, ChildItem, item);
                    }
                }
#else
                foreach (object ChildItem in itemList)
                {
                    InsertChildren(Context, ChildItem, item);
                }
#endif

                Context.Complete();
                Context.Close();
            }

            NotifyCollectionModified(TreeViewCollectionOperation.Insert);
        }
        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();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Inserts child items starting from the content root.
        /// </summary>
        protected override void InsertChildrenFromRootDontNotify()
        {
            if (Content is TItem Item)
            {
                IInsertItemContext Context = CreateInsertItemContext(Item, 0);
                Context.Start();

                InsertChildren(Context, Item, null);

                Context.Complete();
                Context.Close();
            }
        }