Diagram Background mouse click

How do I get a mouse click event when I click in the diagram background, that is not clicking on a node or link but just unused space in the diagram. I don’t get the mouse click below unless I click on a node. I am trying to simulate a unselect link event. If there is a way to get a link is unselected event that would work for me as well.

Grid.Row=“1” x:Name=“myDiagram”
NodeTemplate="{StaticResource NodeTemplate}"
LinkTemplate="{StaticResource LinkTemplate}">


Well, you could data-bind to Diagram.SelectedLink. But that just handles the case only for the primary selection.

Or more generally you could establish a Diagram.SelectedParts.CollectionChanged event handler.

myDiagram.SelectedParts.CollectionChanged += (s, e) => { Debug.WriteLine("selection changed"); };

And in the next release there will be a Diagram.SelectionChanged event.

If you really want to handle mouse events, it might be easier to override a tool method. The selection is changed by the DiagramTool.StandardMouseSelect method, which is called from ClickSelectingTool.DoMouseUp.

So you could override ClickSelectingTool.StandardMouseSelect to do what you want in addition to the base method behavior.

The reason it’s easier to customize tools is because you won’t have to worry about a lot of other cases where a similar mouse event might occur. Defining a mouse event handler on the whole diagram is like hitting at the problem with a bat instead of cutting at it with a scalpel.

And if you really wanted to get mouse events for the whole diagram, you ought to do it on the DiagramPanel, not on the Diagram.

More on the Diagram.SelectionChanged event in version 1.1:

<go:Diagram . . . SelectionChanged="myDiagram_SelectionChanged" />

private void myDiagram_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { String msg = ""; if (e.AddedItems.Count > 0) { msg += "Selected: "; foreach (object x in e.AddedItems) msg += x.ToString() + " "; } if (e.RemovedItems.Count > 0) { msg += "Deselected: "; foreach (object x in e.RemovedItems) msg += x.ToString() + " "; } if (msg.Length > 0) System.Diagnostics.Debug.WriteLine(msg); }