Get Part at a given point


Can you provide some code snippet about how to get Node/Link at a given point in MouseDown event handler?

There are several examples of this in the samples. Look for either MouseDown or MouseLeftButtonDown event handlers.

Hi Walter,

The code I can find is in MouseDown/MouseLButtonDown in DataTemplate of Node. I need code to detect whick Link/Node is clicked when use click the Diagram control.

I try to get Link/Node with DiagramPanel.FindElementAt method. But I always get null when a link is clicked. Is my code correct?


private bool IsPart(DependencyObject element) {

return (element is Part);


private void Diagram_MouseDown(object sender, MouseButtonEventArgs e) {

Func<DependencyObject, Part> testFunc = delegate(DependencyObject element)


return WPFUtil.FindVisualParent<Part>(element);


Part clicked = myDiagram.Panel.FindElementAt<Part>(e.GetPosition(myDiagram), testFunc, IsPart, SearchLayers.All);


Is there a reason you aren’t defining the event handler on the Link itself?

No specific reason. I just want to try hit testing feature with GoWPF.

I suspect the problem with your code above is that it doesn’t call DiagramPanel.TransformViewToModel on the Point you get from e.GetPosition. Furthermore, the coordinates should be relative to the DiagramPanel, not to the Diagram.