Articles in this section
Category / Section

How to add multiple ports for Node in the WPF Diagram (SfDiagram)?

1 min read

The Multiple number of ports can be added to the node by using the PortCollection class in WPF Diagram (SfDiagram).

C#

SfDiagram diagram = new SfDiagram();
diagram.Nodes = new ObservableCollection<NodeViewModel>();
diagram.PortVisibility = PortVisibility.Visible;
 
NodeViewModel node = new NodeViewModel()
{
   UnitHeight = 100,
   UnitWidth = 100,
   OffsetX = 200,
   OffsetY = 200,
   Ports = new PortCollection()
   {
     new NodePortViewModel()
     {
       NodeOffsetX = 0,
       NodeOffsetY = 0,
     },
     new NodePortViewModel()
     {
       NodeOffsetX = 0.5,
       NodeOffsetY = 0,
     },
     new NodePortViewModel()
     {
       NodeOffsetX = 1,
       NodeOffsetY = 0,
     },
     new NodePortViewModel()
     {
       NodeOffsetX = 0,
       NodeOffsetY = 0.5,
     },
     new NodePortViewModel()
     {
       NodeOffsetX = 1,
       NodeOffsetY = 0.5,
     },
     new NodePortViewModel()
     {
       NodeOffsetX = 0,
       NodeOffsetY = 1,
     },
     new NodePortViewModel()
     {
       NodeOffsetX = 0.5,
       NodeOffsetY = 1,
     },
     new NodePortViewModel()
     {
       NodeOffsetX = 1,
       NodeOffsetY = 1,
     },
   },
};
(diagram.Nodes as ObservableCollection<NodeViewModel>).Add(node);

 

A close up of a logo

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