Articles in this section
Category / Section

How to validate the connection and port visibility in WPF Diagram (SfDiagram)?

1 min read

The ValidateConnection is one of the PortVisibility which is used to achieve logical gates functionality in ports, and it controls over visibility of port based on the connector ends in WPF Diagram (SfDiagram).

  • Port which is having OutPort in constraints will be visible only in new connection (Source thumb dragging).
  • Port which is having InPort in constraints will be visible only in end thumb dragging.

The ValidateConnection virtual method is used to make decision on creating/editing the connection at runtime.

  • Restrict the number of connections in port or node.
  • Decide on target/source port or node of connection.

For example, InPort, OutPort, and number of connections to the port restriction is represented in the sample. Refer to the code example and sample as follows.

C#

// Validate the connection when connector endpoints are dragged
protected override void ValidateConnection (ConnectionParameter args)
{
  if (args.TargetPort is PortVM)
  {
    var port = args.TargetPort as PortVM;
    if (!port.CanCreateConnection(args.Connector as IConnector))
    {
      args.TargetPort = null;
    }
  }
  base.ValidateConnection(args);
}

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  to leave a comment
Access denied
Access denied