Articles in this section
Category / Section

How to customize the Selection behavior in WPF Diagram (SfDiagram)?

1 min read

By default, the selection can be done in PointerUp in WPF Diagram (SfDiagram). SfDiagram provides support to customize the Selection behavior that allows selection in PointerDown. This can be achieved by overriding the PointerSelection method in Selector class of SfDiagram. In that, the Selection method is used to select/unselect the Node and Connector in the PointerDown Event. The ClearSelection method is used to clear the selection when the argument source become the SfDiagram. The following code example represents this.

C#

public class CustomSelector : Selector
{       
  //Method to decide whether the Selection should be done in PointerDown.
  protected override void PointerSelection(PointerSelectionArgs args)
  {
    if (args.PointerMode == PointerMode.Down)
    {
      Selection(element: args.Source);
      if (args.Source is SfDiagram)
      {
        ClearSelection(Element: args.Source);
      }
    }
  }
}

And, you need to return this Selector(CustomSelector) class in the GetSelectorForItemOverride() method of Diagram(CustomDiagram). Refer to the following code example.

C#

public class CustomDiagram : SfDiagram
{        
  //Method to return the selector for diagram
  protected override Selector GetSelectorForItemOverride(object item)
  {
            //Assigning custom selector to the diagram
            CustomSelector selector = new CustomSelector();
            return selector;
  }    
}

View sample in GitHub.

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