Esempio n. 1
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;
            }
        }
Esempio n. 2
0
        private void OnTreeViewItemParentChanged(object sender, ParentChangedEventArgs e)
        {
            TreeViewItem treeViewItem1 = (TreeViewItem)sender;

            if (!this.CanHandleEvent((object)treeViewItem1))
            {
                return;
            }
            TreeViewItem oldParent = e.OldParent;

            if (this.DropMarker.Action != ItemDropAction.SetLastChild && this.DropMarker.Action != ItemDropAction.None)
            {
                if (!Object.op_Inequality((Object)oldParent, (Object)null) || oldParent.HasChildren)
                {
                    return;
                }
                oldParent.CanExpand = false;
            }
            else
            {
                TreeViewItem newParent = e.NewParent;
                if (Object.op_Inequality((Object)newParent, (Object)null))
                {
                    if (newParent.CanExpand)
                    {
                        newParent.IsExpanded = true;
                    }
                    else
                    {
                        newParent.CanExpand = true;
                        try
                        {
                            this.m_expandSilently = true;
                            newParent.IsExpanded  = true;
                        }
                        finally
                        {
                            this.m_expandSilently = false;
                        }
                    }
                }
                TreeViewItem child = treeViewItem1.FirstChild();
                TreeViewItem treeViewItem2;
                if (Object.op_Inequality((Object)newParent, (Object)null))
                {
                    treeViewItem2 = newParent.LastChild();
                    if (Object.op_Equality((Object)treeViewItem2, (Object)null))
                    {
                        treeViewItem2 = newParent;
                    }
                }
                else
                {
                    treeViewItem2 = (TreeViewItem)this.LastItemContainer();
                }
                if (Object.op_Inequality((Object)treeViewItem2, (Object)treeViewItem1))
                {
                    TreeViewItem treeViewItem3 = treeViewItem2.LastDescendant();
                    if (Object.op_Inequality((Object)treeViewItem3, (Object)null))
                    {
                        treeViewItem2 = treeViewItem3;
                    }
                    if (!treeViewItem2.IsDescendantOf(treeViewItem1))
                    {
                        base.SetNextSibling((ItemContainer)treeViewItem2, (ItemContainer)treeViewItem1);
                    }
                }
                if (Object.op_Inequality((Object)child, (Object)null))
                {
                    this.MoveSubtree(treeViewItem1, child);
                }
                if (!Object.op_Inequality((Object)oldParent, (Object)null) || oldParent.HasChildren)
                {
                    return;
                }
                oldParent.CanExpand = false;
            }
        }