public void DragTo(NodeViewModel beDrag, NodeViewModel parent, NodeViewModel previousBrother) { NodeViewModel Node = beDrag; INodeViewModel oldParent = Node.Parent; int oldIndex = Node.IndexInParent; if (parent == null) { parent = RootNode; } var newIndex = 0; if (previousBrother != null) { ///如果前一个同级节点为空,那么index则为0 ///否则进入此处逻辑判断 if (previousBrother == Node) { ///如果要拖动到的前一个同级节点就是自己 ///那么index不改变 newIndex = Node.IndexInParent; } else { ///否则如果拖动到的前一个同级节点和自己在同一个父节点下面 if (previousBrother.Parent == Node.Parent) { if (Node.IndexInParent <= previousBrother.IndexInParent) { newIndex = previousBrother.IndexInParent; } else { newIndex = previousBrother.IndexInParent + 1; } } else { newIndex = previousBrother.IndexInParent + 1; } } } if (parent == oldParent && newIndex == oldIndex) { Debug.WriteLine("not changed"); } else { Node.DragTo(parent, newIndex); PageTreeChanged(); } MovePageCommand cmd = new MovePageCommand(Node, Node.Parent, Node.IndexInParent, oldParent, oldIndex); _undoManager.Push(cmd); }
private void PageDownExecute(object cmdParameter) { INodeViewModel Node = NodeInfo.SelectedNode; int oldIndex = Node.IndexInParent; Node.MoveDown(); PageTreeChanged(); MovePageCommand cmd = new MovePageCommand(Node, Node.Parent, Node.IndexInParent, Node.Parent, oldIndex); _undoManager.Push(cmd); if (_pageTree != null) { _pageTree.Focus(); } }