コード例 #1
0
        private void InsertAddedItems(NotifyCollectionChangedEventArgs e)
        {
            if (e.NewItems != null)
            {
                int index         = e.NewStartingIndex;
                int nextItemIndex = index;

                if (!HasChildren)
                {
                    //first child, should be in the treeitem place
                    nextItemIndex = -1;
                }
                else if (index == 0)
                {
                    nextItemIndex = -1;
                }
                else if (index == Children.Count)
                {
                    nextItemIndex = ContainerList.IndexOf(this) + CountVisibleDescendatns();
                }
                else
                {
                    var nextItem = Children[index];
                    nextItemIndex = ContainerList.IndexOf(nextItem) - 1;
                }

                var newChildren = new List <LiteTreeViewItemViewModel>();
                foreach (object obj in e.NewItems)
                {
                    newChildren.Add(AddChild(obj, index));
                    index++;
                }
                FillTreeList(ContainerList, newChildren, ref nextItemIndex);
            }
        }