I want to swap locations of 2 nodes when Node A is Dropped on Node B.
I am doing this in DraggingTool.DropOnto method what is the most reliable way of finding out Node A’s location from where it was dragged so I can set that as location of Node B and move it o Node A’s Location. I dont think I can use FirstMousePointInModel as Node is quite big and has a small rectangle inside it set as LocationElement.
public class SwappingTool : DraggingTool {
private Point OriginalLocation;
public override void DoActivate() {
base.DoActivate();
if (this.CurrentPart is Node) {
this.OriginalLocation = ((Node)this.CurrentPart).Location;
}
}
protected override void DropOnto(Point pt) {
Node overPart = this.Diagram.Panel.FindElementAt<Node>(pt, Part.FindAncestor<Node>, n => (n != this.CurrentPart), SearchLayers.Nodes);
if (overPart != null && this.CurrentPart is Node) {
overPart.Location = this.OriginalLocation;
} else {
base.DropOnto(pt);
}
}
}
Install by setting Diagram.DraggingTool with a new instance of this class, either in code or in XAML.
Thanks Walter
I forgot to mention that you should also deal with multiple selection. This code does not handle that.