Articles in this section
Category / Section

How to Get the Node or Connector in the MouseMove Event in the WPF Diagram (SfDiagram)

2 mins read

In the WPF Diagram (SfDiagram), you can get the node or connector in the mouse move using the FindVisualParent method. This method will help you get the Diagram elements based on the provided source. The following code sample explains how to get the node or connector in the MouseMoveEvent.

Code Snippet:

//Here, the diagram is the instance of the SfDiagram.
//Adding the MouseMove Event.

diagram.MouseMove += Diagram_MouseMove;

/// <summary>
/// Method for executing the MouseMoveEvent.
/// </summary>

private void Diagram_MouseMove(object sender, MouseEventArgs e)
{
  //Caste the e.OriginalSource as a Dependency Object.
  DependencyObject source = e.OriginalSource as DependencyObject;
 
  // Find the Visual Parent for the node.
  var node = source.FindVisualParent<Node>();

  //Find the Visual Parent for the connector.
  var connector = source.FindVisualParent<Connector>();


  if ((node != null))
  {
      //Get the NodeViewModel from the node.
      NodeViewModel nodeVM = node.DataContext as NodeViewModel;
  }
  if(connector != null) 
  { 
      //Get the ConnectorViewModel from the connector.
      ConnectorViewModel connectorVM = connector.DataContext as ConnectorViewModel;
  }
}

View Sample in GitHub

Conclusion:
I hope you enjoyed learning how to get the node or connector in the MouseMove event in the WPF Diagram (SfDiagram).

Refer to our WPF Diagram feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to check out our other controls.

Please let us know in the following comments section if you have any queries or require clarifications. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied