Loading...
Loading...
Build and troubleshoot Syncfusion Blazor diagrams using SfDiagramComponent. Trigger for flowcharts, org charts, mind maps, BPMN, UML sequence, swimlanes, symbol palettes, nodes/connectors/ports/annotations, layouts, data binding, serialization (load/save), export/print, and collaborative editing questions. Provide Blazor + Syncfusion setup steps, configuration patterns, and sample snippets.
npx skill4agent add syncfusion/blazor-ui-components-skills syncfusion-blazor-diagramSfDiagramComponentreferences/*.md@using Syncfusion.Blazor.Diagram
<SfDiagramComponent Width="100%" Height="600px" Nodes="@nodes" Connectors="@connectors" />
@code {
DiagramObjectCollection<Node> nodes = new DiagramObjectCollection<Node>
{
new Node
{
ID = "node1", OffsetX = 150, OffsetY = 150,
Width = 100, Height = 50,
Style = new ShapeStyle { Fill = "#6BA5D7", StrokeColor = "white" },
Annotations = new DiagramObjectCollection<ShapeAnnotation>
{
new ShapeAnnotation { Content = "Start" }
}
}
};
DiagramObjectCollection<Connector> connectors = new DiagramObjectCollection<Connector>
{
new Connector { ID = "conn1", SourceID = "node1", TargetID = "node2" }
};
}| Goal | Reference |
|---|---|
| First diagram setup | references/getting-started.md |
| Add/configure nodes | references/nodes.md |
| Add/configure connectors | references/connectors.md |
| Use built-in shapes | references/shapes.md |
| Add text labels | references/annotations.md |
| Define connection points | references/ports.md |
| Org charts / auto-layout | references/layout.md |
| Swimlane diagrams | references/swimlane.md |
| BPMN process diagrams | references/bpmn.md |
| Drag-and-drop palette | references/symbol-palette.md |
| Bind data to diagram | references/data-binding.md |
| Selection, drag, zoom | references/interaction.md |
| Handle diagram events | references/events.md |
| Save and load diagrams | references/serialization.md |
| Export / print | references/export-print.md |
| CSS / theme styling | references/styling.md |
| UML sequence diagrams | references/uml-sequence.md |
| Real-time collaboration | references/collaborative-editing.md |
| Context menu, tooltips, rulers, localization | references/advanced-features.md |
| Miniature overview / bird's-eye navigation | references/overview-component.md |
Syncfusion.Blazor.Diagram<SfDiagramComponent Height="600px" Swimlanes="@swimlanes" />
@code {
DiagramObjectCollection<Swimlane> swimlanes = new();
protected override void OnInitialized()
{
swimlanes.Add(new Swimlane
{
ID = "swimlane1",
OffsetX = 400, OffsetY = 300,
Width = 600, Height = 200,
Lanes = new DiagramObjectCollection<Lane>()
{
new Lane(){
Height = 100,
Header = new SwimlaneHeader(){
Width = 30,
Annotation = new ShapeAnnotation(){ Content = "Consumer" }
},
Children = new DiagramObjectCollection<Node>()
{
new Node(){Height = 50, Width = 50, LaneOffsetX = 250, LaneOffsetY = 30},
}
},
}
});
}
}// Exclusive gateway (XOR)
nodes.Add(new Node
{
ID = "gateway1", OffsetX = 300, OffsetY = 200, Width = 50, Height = 50,
Shape = new BpmnGateway
{
GatewayType = BpmnGatewayType.Exclusive
}
});SfSymbolPaletteComponentBringIntoView(DiagramRect)BringIntoCenter(DiagramRect)FitToPage(FitOptions?)FitMode.Width/Height/BothDiagramRegion.Content/PageSettingsNudge(Direction, int?)Direction.Top/Bottom/Left/RightBringToFront()BringForward()SendBackward()SendToBack()Select()CommandManagerCommandManagerKeyboardCommandKeyGestureDiagramKeysModifierKeysCommandKeyArgsSetAlignSetDistributeSetSameSizeUndo()Redo()CssClassSfDiagramOverviewComponentSourceIDIDWidthHeightDiagramOverviewConstraints@using Syncfusion.Blazor.Diagram.Overview@using Syncfusion.Blazor.Diagram
@using Syncfusion.Blazor.Diagram.Overview
@using System.Collections.ObjectModel
<SfDiagramComponent ID="element"
Width="100%"
Height="500px">
</SfDiagramComponent>
<!-- Overview panel linked to the diagram above -->
<SfDiagramOverviewComponent Height="150px" SourceID="element" />⚠️does NOT exist onAllowEditingorShapeAnnotation.PathAnnotation
Inline editing is on by default — no property is needed to enable it.
To disable editing, set:Constraints = AnnotationConstraints.ReadOnlycsharp// ❌ Wrong — CS0117: AllowEditing does not exist new ShapeAnnotation { Content = "Label", AllowEditing = false } // ✅ Correct — use AnnotationConstraints.ReadOnly to disable editing new ShapeAnnotation { Content = "Label", Constraints = AnnotationConstraints.ReadOnly }
⚠️ Always use(async) —EndUpdateAsync()(sync, non-async) does NOT exist and will cause a compile error.EndUpdate()
Use/BeginUpdate()when changing multiple properties at once —EndUpdateAsync()is required:awaitcsharp// ❌ Wrong — EndUpdate() does not exist diagram.BeginUpdate(); // ... changes ... diagram.EndUpdate(); // ✅ Correct — EndUpdateAsync is async diagram.BeginUpdate(); // ... changes ... await diagram.EndUpdateAsync();
⚠️name collision: If your page also usesClickEventArgs(or Buttons),@using Syncfusion.Blazor.Navigations
becomes ambiguous. Always qualify it:ClickEventArgscsharp// ✅ Use the fully qualified type in the handler signature private void OnClick(Syncfusion.Blazor.Diagram.ClickEventArgs args) { }
⚠️is NOT anargs.Countfield — it is a method that returns anint.int
Do NOT compare it directly withinline without storing the result first:==csharp// ❌ Wrong — CS0019: Operator '==' cannot be applied to operands of type 'method group' and 'int' if (args.Count == 2) // ✅ Correct — store result then compare int clickCount = args.Count; if (clickCount == 2) { /* double-click */ }
⚠️is typed asSizeChangedEventArgs.Element, notDiagramSelectionSettings.Node
Pattern-matchingalways fails withargs.Element is Node n.CS8121
Cast toand readDiagramSelectionSettingsto get the resized node:.Nodes[0]csharp// ❌ Wrong — CS8121: DiagramSelectionSettings cannot match Node if (args.Element is Node n) { } // ✅ Correct — Element is DiagramSelectionSettings if (args.Element is DiagramSelectionSettings sel && sel.Nodes.Count > 0) { var node = sel.Nodes[0]; double w = args.NewValue.Width; double h = args.NewValue.Height; }
⚠️andargs.NewValue.Widthare plainargs.NewValue.Height, notdouble.double?
Usingon them causes??. Assign them directly:CS0019csharp// ❌ Wrong — CS0019 double w = args.NewValue.Width ?? 0; // ✅ Correct double w = args.NewValue.Width;
⚠️name collision: If your page also usesSelectionChangedEventArgs@using Syncfusion.Blazor.Buttons
(or other Syncfusion packages),becomes ambiguous. Always qualify it:SelectionChangedEventArgscsharp// ✅ Fully qualified private void OnSelectionChanged(Syncfusion.Blazor.Diagram.SelectionChangedEventArgs args) { }
⚠️is aargs.NewValueobject — NOT aDiagramSelectionSettings, NOT a collection:Node
- Pattern-matching
always fails withargs.NewValue is NodeCS8121- Iterating
as a collection fails — it is a single settings objectargs.NewValue- The only correct approach is to read
/_diagram.SelectionSettings.Nodes:.Connectorscsharp// ❌ Wrong — CS8121: DiagramSelectionSettings cannot match Node if (args.NewValue is Node n) { } // ❌ Wrong — DiagramSelectionSettings is not IEnumerable foreach (var item in args.NewValue) { } // ✅ Correct — use SelectionSettings on the diagram reference foreach (var node in _diagram.SelectionSettings.Nodes) Console.WriteLine(node.ID); foreach (var conn in _diagram.SelectionSettings.Connectors) Console.WriteLine(conn.ID);
⚠️does NOT exist — using it causesTextChangedEventArgs.CS0246
The correct event args type is(noTextChangeEventArgs):dcsharp// ❌ Wrong — CS0246: TextChangedEventArgs not found private void OnTextChanged(TextChangedEventArgs args) { } // ✅ Correct private void OnTextChanged(TextChangeEventArgs args) { }
⚠️is ambiguous whenDragStartEventArgs(or other packages that exposeSyncfusion.Blazor.Popups) is also referenced.DragStartEventArgs
Always qualify it as:Syncfusion.Blazor.Diagram.DragStartEventArgscsharp// ❌ Wrong — CS0104: ambiguous reference between Diagram and Popups private void OnDragStart(DragStartEventArgs args) { } // ✅ Correct — fully qualified private void OnDragStart(Syncfusion.Blazor.Diagram.DragStartEventArgs args) { }
⚠️does NOT exist inDragEnterEventArgs.Syncfusion.Blazor.Diagram
There is noevent onDragEnterthat receives aSfDiagramComponent.DragEnterEventArgs
The available drag events onare:SfDiagramComponent,DragStart,Dragging,DragLeave— all for SymbolPalette drag-and-drop only.DragDrop
For tracking when a node is being moved (internal drag), use:PositionChangedcsharp// ❌ Wrong — DragEnterEventArgs does not exist private void OnDragEnter(DragEnterEventArgs args) { } // ❌ Wrong — OnPositionChange does not exist on SfDiagramComponent <SfDiagramComponent OnPositionChange="OnPositionChange" /> // ✅ Correct — use PositionChanged <SfDiagramComponent PositionChanged="OnPositionChanged" /> private void OnPositionChanged(PositionChangedEventArgs args) { if (args.Element is Node n) Console.WriteLine($"Node {n.ID} moved to ({n.OffsetX}, {n.OffsetY})"); }
⚠️does NOT exist onSnapObjectDistance— using it causesSnapSettings.InvalidOperationException: does not have a property matching the name 'SnapObjectDistance'
The correct property name is:SnapDistancerazor@* ❌ Wrong — SnapObjectDistance does not exist *@ <SnapSettings SnapObjectDistance="5" /> @* ✅ Correct *@ <SnapSettings Constraints="SnapConstraints.SnapToObject" SnapDistance="5" />
⚠️does NOT exist onCssClass— using it causesSfDiagramComponent
.InvalidOperationException: Object of type 'SfDiagramComponent' does not have a property matching the name 'CssClass'
Wrap the component in awith a scoping class instead:<div>razor@* ❌ Wrong — CssClass does not exist on SfDiagramComponent *@ <SfDiagramComponent CssClass="my-diagram" /> @* ✅ Correct — use a wrapper div *@ <div class="my-diagram"> <SfDiagramComponent ... /> </div>
⚠️does NOT exist — using it causes a compile error.Phase.Offset
Useto set the size of a phase in a swimlane:Phase.Widthcsharp// ❌ Wrong — Offset does not exist on Phase new Phase { ID = "ph1", Offset = 220 } // ✅ Correct — use Width new Phase { ID = "ph1", Width = 220 }
⚠️does NOT exist andLane.Constraintsenum does NOT exist.LaneConstraints
Individual lanes cannot have constraints set via aproperty.Constraints
To restrict swimlane-level interactions, useon theSwimlaneConstraintsobject itself:Swimlanecsharp// ❌ Wrong — Lane.Constraints and LaneConstraints do not exist lane.Constraints = LaneConstraints.Default & ~LaneConstraints.ResizeEntries; // ✅ Correct — set constraints on the Swimlane object swimlane.Constraints = SwimlaneConstraints.Default & ~SwimlaneConstraints.Interaction;
⚠️does NOT exist — using it causesFitMode.Page.CS0117
The correct values forareFitModeandFitMode.Width:FitMode.Heightcsharp// ❌ Wrong — FitMode.Page does not exist new FitOptions { Mode = FitMode.Page } // ✅ Correct — use FitMode.Width or FitMode.Height new FitOptions { Mode = FitMode.Width, Region = DiagramRegion.Content }
⚠️does NOT exist — using it causes a compile error.SfDiagramComponent.LoadDiagram()
Use the async versioninstead:LoadDiagramAsync()csharp// ❌ Wrong — LoadDiagram() does not exist diagram.LoadDiagram(savedJson); // ✅ Correct — use LoadDiagramAsync await diagram.LoadDiagramAsync(savedJson);
⚠️does NOT exist — using it causes a compile error.SfDiagramComponent.FitToPageAsync()
Use the non-async overloadinstead:FitToPage()csharp// ❌ Wrong — FitToPageAsync does not exist await diagram.FitToPageAsync(new FitOptions { Mode = FitMode.Width }); // ✅ Correct — use FitToPage (synchronous) diagram.FitToPage(new FitOptions { Mode = FitMode.Width, Region = DiagramRegion.Content });
⚠️does NOT exist — useBasicShapesinstead:NodeBasicShapescsharp// ❌ Wrong new BasicShape { Shape = BasicShapes.Rectangle } // ✅ Correct new BasicShape { Shape = NodeBasicShapes.Rectangle }
⚠️does NOT have a 4-argument constructor — using it causesDiagramThickness.CS1729: does not contain a constructor that takes 4 arguments
Use the object initializer syntax with named properties instead:csharp// ❌ Wrong — CS1729: no 4-argument constructor new DiagramThickness(20, 50, 20, 20) // ✅ Correct — use object initializer with named properties new DiagramThickness { Left = 20, Top = 50, Right = 20, Bottom = 20 } // ✅ Correct — set only the sides you need new DiagramThickness { Top = 50 }
⚠️does NOT exist onCanAutoScroll— using it causesScrollSettings.InvalidOperationException: does not have a property matching the name 'CanAutoScroll'
The correct property name is:EnableAutoScrollrazor@* ❌ Wrong — CanAutoScroll does not exist *@ <ScrollSettings CanAutoScroll="true" /> @* ✅ Correct *@ <ScrollSettings EnableAutoScroll="true" />
⚠️,ZoomAsync(), andUndoAsync()do NOT exist — using them causes a compile error.RedoAsync()
Use the non-async overloads,Zoom(), andUndo()instead:Redo()csharp// ❌ Wrong — ZoomAsync, UndoAsync, RedoAsync do not exist await _diagram.ZoomAsync(1.2, new DiagramPoint { X = 300, Y = 300 }); await _diagram.UndoAsync(); await _diagram.RedoAsync(); // ✅ Correct — use non-async overloads _diagram.Zoom(1.2, new DiagramPoint { X = 300, Y = 300 }); _diagram.Undo(); _diagram.Redo();
⚠️requires an additionalSfDiagramOverviewComponent— it lives in@using, NOT inSyncfusion.Blazor.Diagram.Overview. Forgetting it causesSyncfusion.Blazor.Diagram:CS0246razor@* ❌ Wrong — SfDiagramOverviewComponent not found without the Overview namespace *@ @using Syncfusion.Blazor.Diagram @* ✅ Correct — both namespaces required *@ @using Syncfusion.Blazor.Diagram @using Syncfusion.Blazor.Diagram.Overview
⚠️must exactly match theSourceIDset onID— theSfDiagramComponentis NOT auto-generated; you must set it explicitly. A mismatch (including case) renders the overview empty:IDrazor@* ❌ Wrong — ID not set on the diagram; SourceID has nothing to link to *@ <SfDiagramComponent Width="100%" Height="500px" Nodes="@_nodes" /> <SfDiagramOverviewComponent SourceID="myDiagram" Height="150px" /> @* ✅ Correct — ID set on diagram, SourceID matches exactly *@ <SfDiagramComponent ID="myDiagram" Width="100%" Height="500px" Nodes="@_nodes" /> <SfDiagramOverviewComponent SourceID="myDiagram" Height="150px" />
⚠️ Do NOT nestinsideSfDiagramOverviewComponent— the overview is a sibling component rendered outside the diagram markup.SfDiagramComponent