1+ @page " /AddAsyncMethod"
2+
3+ @using Syncfusion .Blazor .Diagram
4+ @using Syncfusion .Blazor .Buttons
5+
6+ <SfButton Content =" Add Port and Annotation" OnClick =" @AddPortAndAnnotationAsync" />
7+
8+ <SfDiagramComponent @ref =" _diagram" Width =" 900px" Height =" 500px" Nodes =" @_nodes" Connectors =" @_connectors" >
9+ </SfDiagramComponent >
10+
11+ @code
12+ {
13+ // Reference the diagram.
14+ private SfDiagramComponent _diagram ;
15+
16+ // Initialize the nodes and connectors collections.
17+ private DiagramObjectCollection <Node > _nodes = new DiagramObjectCollection <Node >();
18+ private DiagramObjectCollection <Connector > _connectors = new DiagramObjectCollection <Connector >();
19+
20+ protected override void OnInitialized ()
21+ {
22+ Node node = new Node ()
23+ {
24+ ID = " node1" ,
25+ OffsetX = 300 ,
26+ OffsetY = 200 ,
27+ Width = 120 ,
28+ Height = 60 ,
29+ Style = new ShapeStyle () { Fill = " #6495ED" , StrokeColor = " #6495ED" },
30+ Shape = new BasicShape () { Type = NodeShapes .Basic , Shape = NodeBasicShapes .Rectangle },
31+ };
32+
33+ _nodes .Add (node );
34+ }
35+
36+ private async Task AddPortAndAnnotationAsync ()
37+ {
38+ Node node = _diagram .Nodes [0 ];
39+
40+ await node .Ports .AddAsync (new PointPort ()
41+ {
42+ ID = " port1" ,
43+ Offset = new DiagramPoint () { X = 1 , Y = 0 . 5 },
44+ Visibility = PortVisibility .Visible ,
45+ Height = 10 ,
46+ Width = 10 ,
47+ Style = new ShapeStyle () { Fill = " #FFFFFF" , StrokeColor = " #1F3A93" },
48+ Shape = PortShapes .Custom ,
49+ // Sets the PathData for port.
50+ PathData = " M540.3643,137.9336L546.7973,159.7016L570.3633,159.7296L550.7723,171.9366L558.9053,194.9966L540.3643,179.4996L521.8223,194.9966L529.9553,171.9366L510.3633,159.7296L533.9313,159.7016L540.3643,137.9336z"
51+ });
52+
53+ await node .Annotations .AddAsync (new ShapeAnnotation ()
54+ {
55+ Content = " Node 1" ,
56+ Offset = new DiagramPoint () { X = 0 . 5 , Y = 0 . 5 }
57+ });
58+ }
59+ }
0 commit comments