Articles in this section
Category / Section

How to override the default cursors while interaction in WPF Diagram (SfDiagram)?

3 mins read

The default cursors can be modified by overriding the virtual method SetCursor() of the WPF Diagram (SfDiagram) class. The SetCursor() method takes the SetCursorArgs as an argument that is used to know the objects under the mouse cursor when modifying the cursors of them.

  • Source –  To know the object on which item the mouse is interacting.
  • Action –  To know the action tool of the element.
  • SourceType –  To know the parent element of the object.
  • ControlPointType  –  To know the control point of the object.
  • CursorTo customize the cursor of the object.

XAML

<local:CustomClass PortVisibility="Visible" x:Name="diagram"/>

C#

public class CustomClass : SfDiagram
{
  protected override void SetCursor(SetCursorArgs args)
  {
    if (args.Source is INode)
    {
      args.Cursor = Cursors.No;
    }
    else if (args.Source is IConnector)
    {
      args.Cursor = Cursors.Hand;
    }
    else if (args.Source is IPort)
    {
      args.Cursor = Cursors.SizeAll;
    }
    else
    {
      base.SetCursor(args);
    }
  }
}

 

A picture containing game, table

Description automatically generated

View Sample in GitHub

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