Exemple #1
0
        protected override void SetNextSibling(ItemContainer sibling, ItemContainer nextSibling)
        {
            TreeViewItem treeViewItem1 = (TreeViewItem)sibling;
            TreeViewItem treeViewItem2 = treeViewItem1.LastDescendant();

            if (Object.op_Equality((Object)treeViewItem2, (Object)null))
            {
                treeViewItem2 = treeViewItem1;
            }
            TreeViewItem parent = (TreeViewItem)nextSibling;
            TreeViewItem child  = parent.FirstChild();

            base.SetNextSibling((ItemContainer)treeViewItem2, nextSibling);
            if (Object.op_Inequality((Object)child, (Object)null))
            {
                this.MoveSubtree(parent, child);
            }
            parent.Parent = treeViewItem1.Parent;
        }
Exemple #2
0
        protected override void SetNextSibling(ItemContainer sibling, ItemContainer nextSibling)
        {
            TreeViewItem tvSibling      = (TreeViewItem)sibling;
            TreeViewItem lastDescendant = tvSibling.LastDescendant();

            if (lastDescendant == null)
            {
                lastDescendant = tvSibling;
            }
            TreeViewItem tvItem        = (TreeViewItem)nextSibling;
            TreeViewItem dragItemChild = tvItem.FirstChild();

            base.SetNextSibling(lastDescendant, nextSibling);

            if (dragItemChild != null)
            {
                MoveSubtree(tvItem, dragItemChild);
            }

            tvItem.Parent = tvSibling.Parent;
        }
Exemple #3
0
        /// <summary>
        /// Add data item as last child of parent
        /// </summary>
        /// <param name="parent">parent data item</param>
        /// <param name="item">data item to add</param>
        public void AddChild(object parent, object item)
        {
            if (parent == null)
            {
                Add(item);
            }
            else
            {
                TreeViewItem parentContainer = (TreeViewItem)GetItemContainer(parent);
                if (parentContainer == null)
                {
                    return;
                }

                int index = -1;
                if (parentContainer.IsExpanded)
                {
                    if (parentContainer.HasChildren)
                    {
                        TreeViewItem lastDescendant = parentContainer.LastDescendant();
                        index = IndexOf(lastDescendant.Item) + 1;
                    }
                    else
                    {
                        index = IndexOf(parentContainer.Item) + 1;
                    }
                }
                else
                {
                    parentContainer.CanExpand = true;
                }

                if (index > -1)
                {
                    TreeViewItem addedItem = (TreeViewItem)Insert(index, item);
                    addedItem.Parent = parentContainer;
                }
            }
        }
Exemple #4
0
        private void OnTreeViewItemParentChanged(object sender, ParentChangedEventArgs e)
        {
            TreeViewItem tvItem = (TreeViewItem)sender;

            if (!CanHandleEvent(tvItem))
            {
                return;
            }

            TreeViewItem oldParent = e.OldParent;

            if (DropMarker.Action != ItemDropAction.SetLastChild && DropMarker.Action != ItemDropAction.None)
            {
                if (oldParent != null && !oldParent.HasChildren)
                {
                    oldParent.CanExpand = false;
                }
                return;
            }

            TreeViewItem tvDropTarget = e.NewParent;

            if (tvDropTarget != null)
            {
                if (tvDropTarget.CanExpand)
                {
                    tvDropTarget.IsExpanded = true;
                }
                else
                {
                    tvDropTarget.CanExpand = true;
                    try
                    {
                        m_expandSilently        = true;
                        tvDropTarget.IsExpanded = true;
                    }
                    finally
                    {
                        m_expandSilently = false;
                    }
                }
            }

            TreeViewItem dragItemChild = tvItem.FirstChild();
            TreeViewItem lastChild     = null;

            if (tvDropTarget != null)
            {
                lastChild = tvDropTarget.LastChild();
                if (lastChild == null)
                {
                    lastChild = tvDropTarget;
                }
            }
            else
            {
                lastChild = (TreeViewItem)LastItemContainer();
            }

            if (lastChild != tvItem)
            {
                TreeViewItem lastDescendant = lastChild.LastDescendant();
                if (lastDescendant != null)
                {
                    lastChild = lastDescendant;
                }

                if (!lastChild.IsDescendantOf(tvItem))
                {
                    base.SetNextSibling(lastChild, tvItem);
                }
            }

            if (dragItemChild != null)
            {
                MoveSubtree(tvItem, dragItemChild);
            }

            if (oldParent != null && !oldParent.HasChildren)
            {
                oldParent.CanExpand = false;
            }
        }
Exemple #5
0
 public void AddChild(object parent, object item)
 {
     if (parent == null)
     {
         this.Add(item);
     }
     else
     {
         TreeViewItem itemContainer = (TreeViewItem)this.GetItemContainer(parent);
         if (Object.op_Equality((Object)itemContainer, (Object)null))
         {
             return;
         }
         int index = -1;
         if (itemContainer.IsExpanded)
         {
             index = !itemContainer.HasChildren ? this.IndexOf(itemContainer.Item) + 1 : this.IndexOf(itemContainer.LastDescendant().Item) + 1;
         }
         else
         {
             itemContainer.CanExpand = true;
         }
         if (index <= -1)
         {
             return;
         }
         ((TreeViewItem)this.Insert(index, item)).Parent = itemContainer;
     }
 }