/// <summary> /// Creates sample data. /// </summary> private void CreateInitialData() { root_ = new Node_Base("Root"); Node_Base source = new Node_Group("Source") { Index = 0 }; for (int i = 0; i < 4; i++) { source.Children.Add(new Node_Cell(GetNewCellName())); } root_.Children.Add(source); Node_Base destination = new Node_Group("Destination") { Index = 1 }; for (int i = 0; i < 4; i++) { destination.Children.Add(new Node_Cell(GetNewCellName())); } root_.Children.Add(destination); root_.UpdateIndexes(); }
private void TreeView_MouseMove(object sender, MouseEventArgs e) { if (e.LeftButton != MouseButtonState.Pressed) { return; } Point currentPosition = e.GetPosition(TheTreeView); // Note: This should be based on some accessibility number and not just 2 pixels if ((Math.Abs(currentPosition.X - _lastMouseDown.X) > 5.0) || (Math.Abs(currentPosition.Y - _lastMouseDown.Y) > 5.0)) { Node_Base selectedItem = (Node_Base)TheTreeView.SelectedItem; sourceNode_ = selectedItem; Console.WriteLine("TreeView_MouseMove >>> selectedItem = " + selectedItem.Name); if (selectedItem == null) { return; } //TreeViewItem container = (TreeViewItem)(TheTreeView.ItemContainerGenerator.ContainerFromIndex(TheTreeView.Items.CurrentPosition)); TreeViewItem container = (TreeViewItem)(TheTreeView.ItemContainerGenerator.ContainerFromItem(sourceNode_)); container = GetTreeViewItem(e.GetPosition(TheTreeView)); if (container == null) { return; } IsDragInProgress = true; DragDropEffects finalDropEffect = DragDrop.DoDragDrop(container, selectedItem, DragDropEffects.Move); IsDragInProgress = false; // check if we are trying to drop a node onto one of its children if (selectedItem.ContainsNode(targetNode_)) { return; } if (selectedItem == targetNode_) { return; } // verificare che il target non sia figlio del selectedItem if ((finalDropEffect == DragDropEffects.Move) && (targetNode_ != null)) { #region A Move drop was accepted selectedItem.Parent.Children.Remove(selectedItem); switch (targetDropArea_) { case Node_Base.enItemDropArea.Top: targetNode_.Parent.Children.Insert(targetNode_.Index, selectedItem); break; case Node_Base.enItemDropArea.Center: targetNode_.Children.Add(selectedItem); break; case Node_Base.enItemDropArea.Bottom: targetNode_.Parent.Children.Insert(targetNode_.Index + 1, selectedItem); break; default: break; } SelectNode(selectedItem); #endregion } root_.UpdateIndexes(); sourceNode_ = null; targetNode_ = null; IsDragInProgress = false; } }