Event for node or selection moving?

What event can I subscribe to get notified that a node or selection is moving? SelectionMoved fires when the user releases the mouse, but how can I get notifications while the selection is still being dragged?

There are several possible answers to your question, depending on what you really want to achieve.

The most literal answer is that there isn’t any event, but that DraggingTool.MoveParts is called during the drag. So you could override this method and replace Diagram.DraggingTool with an instance of your custom dragging tool class.

Another way to answer this question is that if you have data-bound the go:Node.Location="{Binding Path=Data.Location, Mode=TwoWay}", you could detect the property changes in a …Model.Changed event handler.

But depending on what you want to accomplish, you might want to consider two behaviors that the DraggingTool supports: snapping and drag-over/drop-onto.

Snapping behavior is where during the drag the movement of each node may be guided or restricted by a grid or by other stationary nodes.

Drop-onto behavior can automatically add nodes to groups or connect nodes to nodes when dropped. The associated drag-over behavior automatically sets the Part.IsDropOntoAccepted property on stationary parts. You can customize the appearance of those parts by data-binding to the Part.IsDropOntoAccepted property.

Typically that is used to highlight nodes or links upon which dropping a node will result is interesting behavior, such as adding the node to a group, or such as creating a new link between the dropped node and the stationary node.

I have a similar requirement relating to palettes. I’m trying to create a palette that appears when the user moves the mouse to a particular part of the page (so far so good) but then disappears again as soon as the user starts dragging a palette item onto the diagram. I can use the MoveParts technique you describe to hide the palette as soon as the item appears in the diagram, but I’d really like to have the palette disappear as soon as the user starts dragging in the palette. I find that if I provide the palette with a custom DraggingTool, its MoveParts doesn’t get called. Can you suggest any alternative way to achieve this effect?

In a palette MoveParts isn’t being called because it’s read-only, so no nodes are actually being moved.

Instead of overriding MoveParts in the palette’s custom DraggingTool, I suggest hiding the palette in an override of DraggingTool.DoActivate. Don’t forget to call the base method afterwards.

Thanks very much, that does the trick very nicely.