示例#1
0
        private void MoveNode( Node nodeToMove, Node targetNode, MoveOperation operation )
        {
            var siblings = (NodeCollection)targetNode.Parent.Children;
            var dropPos = siblings.IndexOf( targetNode );

            if ( operation == MoveOperation.MoveAfter )
            {
                dropPos++;
            }

            if ( siblings.Contains( nodeToMove ) )
            {
                var oldPos = siblings.IndexOf( nodeToMove );
                if ( oldPos < dropPos )
                {
                    // ObservableCollection first removes the item and then reinserts which invalidates the index
                    dropPos--;
                }

                siblings.Move( oldPos, dropPos );
            }
            else
            {
                if ( dropPos < siblings.Count )
                {
                    siblings.Insert( dropPos, nodeToMove );
                }
                else
                {
                    siblings.Add( nodeToMove );
                }
            }

            IsDirty = true;
        }
示例#2
0
 internal INode CreateChild( INode parent )
 {
     try
     {
         var node = new Node();
         ( ( Node )parent ).Children.Add( node );
         return node;
     }
     finally
     {
         IsDirty = true;
     }
 }