AutomaticPortCreation in WPF Diagram (SfDiagram)

11 Jan 20241 minute to read

Diagram provides an option to create a port dynamically by clicking and dragging the mouse over any node or connector. This behavior is disabled by default and can be enabled by using GraphConstraints.AutomaticPortCreation. To draw connector, you need to set the Tool and DrawingTool properties of diagram.

<!--Enables AutomaticPortCreation of SfDiagram to create port at runtime while making connections.-->
<syncfusion:SfDiagram x:Name="diagram" PortVisibility="Visible" 
                      Tool="ContinuesDraw" DrawingTool="Connector" 
                      Constraints="Default,AutomaticPortCreation"/>
//We need to enable tool and drawingtool to draw connector by clicking and dragging the mouse over the node.
diagram.Tool = Tool.ContinuesDraw;
diagram.DrawingTool = DrawingTool.Connector;
//Enables AutomaticPortCreation of SfDiagram to create port at runtime while making connections.
diagram.Constraints |= GraphConstraints.AutomaticPortCreation;

WPF Diagram Automatic Port Creation

View Sample in GitHub

Port Dragging

Diagram provides the support to drag the port interactively within the limit.

WPF Diagram Port Dragging

See Also

How to decide whether to drag or draw a port at runtime?

How to create port at runtime though SetTool?