syncfusion-blazor-diagram

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Implementing Syncfusion Blazor Diagram

实现Syncfusion Blazor Diagram

A comprehensive skill for building interactive diagrams with the Syncfusion Blazor Diagram component — flowcharts, organizational charts, mind maps, BPMN process diagrams, UML sequence diagrams, network diagrams, and more.
这是一份使用Syncfusion Blazor Diagram组件构建交互式图表的综合指南——涵盖流程图、组织结构图、思维导图、BPMN流程图表、UML序列图、网络图表等多种类型。

When to Use This Skill

何时使用本技能

Use this skill when you need to:
  • Create flowcharts, org charts, mind maps, or network diagrams in Blazor
  • Work with
    SfDiagramComponent
    , nodes, connectors, or shapes
  • Configure automatic layouts (hierarchical, radial, mind map, org chart, flowchart)
  • Implement BPMN process diagrams with BPMN shapes
  • Build swimlane diagrams for process modeling
  • Add symbol palettes for drag-and-drop diagram building
  • Bind diagram data from a collection or remote source
  • Implement diagram interactions (selection, drag, resize, zoom, pan)
  • Export diagrams to PNG/JPEG/SVG or print them
  • Serialize and restore diagram state (save/load)
  • Enable collaborative real-time editing
  • Add UML sequence diagrams
  • Handle diagram events, annotations, and ports
当你需要完成以下任务时,可使用本技能:
  • 在Blazor中创建流程图、组织结构图、思维导图或网络图表
  • 操作
    SfDiagramComponent
    、节点、连接线或形状
  • 配置自动布局(层级布局、放射状布局、思维导图布局、组织结构图布局、流程图布局)
  • 使用BPMN形状实现BPMN流程图表
  • 构建用于流程建模的泳道图
  • 添加支持拖放的符号面板以创建图表
  • 将图表数据与集合或远程数据源绑定
  • 实现图表交互(选择、拖拽、调整大小、缩放、平移)
  • 将图表导出为PNG/JPEG/SVG格式或打印
  • 序列化和恢复图表状态(保存/加载)
  • 启用实时协同编辑
  • 添加UML序列图
  • 处理图表事件、注释和端口

Important: API Verification Required

重要提示:需验证API

API Verification Required: Always verify API class names, properties, and signatures by reading reference files (
references/*.md
) BEFORE generating code examples. Do not assume or infer class names. ⚠️ Before writing ANY code, review the Common Mistakes section directly below to avoid known invalid APIs and properties.
必须验证API:在生成代码示例之前,请务必通过参考文件(
references/*.md
)验证API类名、属性和签名。请勿假设或推断类名。 ⚠️ 在编写任何代码之前,请直接查看下方的常见错误部分,避免使用已知的无效API和属性。

Quick Start

快速开始

razor
@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" }
    };
}
razor
@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" }
    };
}

Common Patterns

常见模式

GoalReference
First diagram setupreferences/getting-started.md
Add/configure nodesreferences/nodes.md
Add/configure connectorsreferences/connectors.md
Use built-in shapesreferences/shapes.md
Add text labelsreferences/annotations.md
Define connection pointsreferences/ports.md
Org charts / auto-layoutreferences/layout.md
Swimlane diagramsreferences/swimlane.md
BPMN process diagramsreferences/bpmn.md
Drag-and-drop palettereferences/symbol-palette.md
Bind data to diagramreferences/data-binding.md
Selection, drag, zoomreferences/interaction.md
Handle diagram eventsreferences/events.md
Save and load diagramsreferences/serialization.md
Export / printreferences/export-print.md
CSS / theme stylingreferences/styling.md
UML sequence diagramsreferences/uml-sequence.md
Real-time collaborationreferences/collaborative-editing.md
Context menu, tooltips, rulers, localizationreferences/advanced-features.md
Miniature overview / bird's-eye navigationreferences/overview-component.md

目标参考文档
首个图表设置references/getting-started.md
添加/配置节点references/nodes.md
添加/配置连接线references/connectors.md
使用内置形状references/shapes.md
添加文本标签references/annotations.md
定义连接点references/ports.md
组织结构图 / 自动布局references/layout.md
泳道图references/swimlane.md
BPMN流程图表references/bpmn.md
拖放面板references/symbol-palette.md
图表数据绑定references/data-binding.md
选择、拖拽、缩放references/interaction.md
处理图表事件references/events.md
保存和加载图表references/serialization.md
导出 / 打印references/export-print.md
CSS / 主题样式references/styling.md
UML序列图references/uml-sequence.md
实时协同编辑references/collaborative-editing.md
上下文菜单、工具提示、标尺、本地化references/advanced-features.md
缩略图概览 / 鹰眼导航references/overview-component.md

Documentation and Navigation Guide

文档与导航指南

Getting Started

入门指南

📄 Read: references/getting-started.md
  • NuGet package installation (
    Syncfusion.Blazor.Diagram
    )
  • Service registration and namespace imports
  • Setup for Blazor Server, WebAssembly, MAUI
  • CSS/theme configuration
  • Minimal working diagram example
📄 阅读: references/getting-started.md
  • NuGet包安装(
    Syncfusion.Blazor.Diagram
  • 服务注册和命名空间导入
  • Blazor Server、WebAssembly、MAUI的设置
  • CSS/主题配置
  • 最简可运行图表示例

Nodes

节点

📄 Read: references/nodes.md
  • Creating and configuring nodes
  • Node types: basic, flow shape, path, image, HTML, native
  • Node positioning, sizing, z-order
  • Node style (fill, stroke, opacity)
  • Expand/collapse children
  • Node events and interaction
📄 阅读: references/nodes.md
  • 创建和配置节点
  • 节点类型:基础节点、流程形状、路径、图片、HTML、原生节点
  • 节点定位、大小调整、层级顺序
  • 节点样式(填充、描边、透明度)
  • 展开/折叠子节点
  • 节点事件与交互

Connectors

连接线

📄 Read: references/connectors.md
  • Creating connectors between nodes or free-floating
  • Segment types: straight, orthogonal, bezier
  • Multiple segments per connector
  • Arrows, line style, and decoration
  • Connector interaction (bend, drag endpoints)
  • Connector events
📄 阅读: references/connectors.md
  • 创建节点间或自由浮动的连接线
  • 线段类型:直线、正交线、贝塞尔曲线
  • 单条连接线包含多个线段
  • 箭头、线条样式和装饰
  • 连接线交互(弯曲、拖拽端点)
  • 连接线事件

Shapes

形状

📄 Read: references/shapes.md
  • Built-in basic shapes (rectangle, ellipse, triangle, etc.)
  • Flow shapes (process, decision, terminator, etc.)
  • Path shapes (custom SVG paths)
  • Image and HTML content shapes
  • Native SVG shapes
  • Choosing the right shape type
📄 阅读: references/shapes.md
  • 内置基础形状(矩形、椭圆、三角形等)
  • 流程形状(流程、决策、终止符等)
  • 路径形状(自定义SVG路径)
  • 图片和HTML内容形状
  • 原生SVG形状
  • 选择合适的形状类型

Annotations

注释

📄 Read: references/annotations.md
  • Adding text labels to nodes and connectors
  • Annotation positioning and alignment
  • Font, color, and style customization
  • Inline editing of annotations
  • Multiple annotations per element
  • Annotation interaction events
📄 阅读: references/annotations.md
  • 为节点和连接线添加文本标签
  • 注释定位与对齐
  • 字体、颜色和样式自定义
  • 注释的在线编辑
  • 单个元素添加多个注释
  • 注释交互事件

Ports

端口

📄 Read: references/ports.md
  • Connection ports (fixed connection points on nodes)
  • Dynamic ports (created at runtime)
  • Port positioning (relative and absolute)
  • Port appearance and visibility
  • Restricting connections to specific ports
📄 阅读: references/ports.md
  • 连接端口(节点上的固定连接点)
  • 动态端口(运行时创建)
  • 端口定位(相对定位和绝对定位)
  • 端口外观与可见性
  • 限制仅与特定端口连接

Layout

布局

📄 Read: references/layout.md
  • Automatic layout overview and when to use each type
  • Hierarchical tree layout (top-down, left-right)
  • Organizational chart layout
  • Mind map layout
  • Radial tree layout
  • Flowchart layout
  • Force-directed tree layout
  • Complex hierarchical layout
  • Layout spacing, margin, and orientation settings
  • Layout events and callbacks
📄 阅读: references/layout.md
  • 自动布局概述及各布局的适用场景
  • 层级树布局(自上而下、自左至右)
  • 组织结构图布局
  • 思维导图布局
  • 放射状树布局
  • 流程图布局
  • 力导向树布局
  • 复杂层级布局
  • 布局间距、边距和方向设置
  • 布局事件与回调

Swimlane

泳道图

📄 Read: references/swimlane.md
  • Creating swimlane diagrams
  • Adding lanes and configuring lane properties
  • Phase configuration (vertical/horizontal phases)
  • Swimlane symbol palette integration
  • Swimlane interactions
razor
<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},
                }
                },
            }
        });
    }
}
📄 阅读: references/swimlane.md
  • 创建泳道图
  • 添加泳道并配置泳道属性
  • 阶段配置(垂直/水平阶段)
  • 泳道符号面板集成
  • 泳道交互
razor
<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},
                }
                },
            }
        });
    }
}

BPMN

BPMN

📄 Read: references/bpmn.md
  • BPMN shape types (events, activities, gateways, data)
  • BPMN event types (start, end, intermediate, boundary)
  • BPMN activity types (task, subprocess, call activity)
  • BPMN gateway types (exclusive, parallel, inclusive, etc.)
  • BPMN connectors (sequence flow, message flow, association)
  • Data objects and data stores
  • Expanded sub-process
  • BPMN text annotation
razor
// Exclusive gateway (XOR)
nodes.Add(new Node
{
    ID = "gateway1", OffsetX = 300, OffsetY = 200, Width = 50, Height = 50,
    Shape = new BpmnGateway
    {
        GatewayType = BpmnGatewayType.Exclusive
    }
});
📄 阅读: references/bpmn.md
  • BPMN形状类型(事件、活动、网关、数据)
  • BPMN事件类型(开始、结束、中间、边界)
  • BPMN活动类型(任务、子流程、调用活动)
  • BPMN网关类型(排他网关、并行网关、包容网关等)
  • BPMN连接线(序列流、消息流、关联)
  • 数据对象和数据存储
  • 展开子流程
  • BPMN文本注释
razor
// 排他网关(XOR)
nodes.Add(new Node
{
    ID = "gateway1", OffsetX = 300, OffsetY = 200, Width = 50, Height = 50,
    Shape = new BpmnGateway
    {
        GatewayType = BpmnGatewayType.Exclusive
    }
});

Symbol Palette

符号面板

📄 Read: references/symbol-palette.md
  • Setting up
    SfSymbolPaletteComponent
  • Defining palette groups and symbols
  • Custom symbols and stencils
  • Drag-and-drop from palette to diagram
  • Palette search and customization
📄 阅读: references/symbol-palette.md
  • 设置
    SfSymbolPaletteComponent
  • 定义面板组和符号
  • 自定义符号和模板
  • 从面板拖放至图表
  • 面板搜索与自定义

Data Binding

数据绑定

📄 Read: references/data-binding.md
  • Binding diagram from a flat list or IEnumerable
  • Hierarchical data binding (parent-child relationships)
  • Remote data source integration
  • CRUD operations on bound data
  • Mapping data fields to node/connector properties
📄 阅读: references/data-binding.md
  • 将图表与扁平列表或IEnumerable绑定
  • 层级数据绑定(父子关系)
  • 远程数据源集成
  • 绑定数据的CRUD操作
  • 数据字段与节点/连接线属性的映射

Interaction & Commands

交互与命令

📄 Read: references/interaction.md
  • Selection modes (single, multiple, rubber-band)
  • Drag, resize, and rotate elements
  • Zoom and pan (mouse wheel, toolbar, programmatic)
  • BringIntoView(DiagramRect)
    — scroll viewport to show a region
  • BringIntoCenter(DiagramRect)
    — scroll viewport to center a region
  • FitToPage(FitOptions?)
    — fit content to viewport (sync;
    FitMode.Width/Height/Both
    ,
    DiagramRegion.Content/PageSettings
    )
  • Nudge(Direction, int?)
    — move selected elements by pixels; default 1px;
    Direction.Top/Bottom/Left/Right
  • Z-Order:
    BringToFront()
    ,
    BringForward()
    ,
    SendBackward()
    ,
    SendToBack()
    — must
    Select()
    first
  • Keyboard shortcuts (built-in table) and
    CommandManager
    (custom/override shortcuts via child component)
  • CommandManager
    uses
    KeyboardCommand
    +
    KeyGesture
    (
    DiagramKeys
    +
    ModifierKeys
    ) +
    CommandKeyArgs
  • Snapping to grid or objects
  • Alignment, spacing, and sizing commands (
    SetAlign
    ,
    SetDistribute
    ,
    SetSameSize
    — all sync)
  • User handles (custom action buttons on selection)
  • Undo/redo (
    Undo()
    ,
    Redo()
    — sync)
📄 阅读: references/interaction.md
  • 选择模式(单选、多选、框选)
  • 拖拽、调整大小和旋转元素
  • 缩放和平移(鼠标滚轮、工具栏、程序化操作)
  • BringIntoView(DiagramRect)
    — 滚动视口以显示指定区域
  • BringIntoCenter(DiagramRect)
    — 滚动视口以将指定区域居中
  • FitToPage(FitOptions?)
    — 将内容适配到视口(同步操作;
    FitMode.Width/Height/Both
    DiagramRegion.Content/PageSettings
  • Nudge(Direction, int?)
    — 按像素移动选中元素;默认1px;
    Direction.Top/Bottom/Left/Right
  • 层级顺序:
    BringToFront()
    BringForward()
    SendBackward()
    SendToBack()
    — 必须先执行
    Select()
  • 键盘快捷键(内置表格)和
    CommandManager
    (通过子组件自定义/覆盖快捷键)
  • CommandManager
    使用
    KeyboardCommand
    +
    KeyGesture
    DiagramKeys
    +
    ModifierKeys
    ) +
    CommandKeyArgs
  • 对齐到网格或对象
  • 对齐、间距和大小调整命令(
    SetAlign
    SetDistribute
    SetSameSize
    — 均为同步操作)
  • 用户操作手柄(选中元素上的自定义操作按钮)
  • 撤销/重做(
    Undo()
    Redo()
    — 同步操作)

Events

事件

📄 Read: references/events.md
  • Diagram-level events (Created, Click, Drop)
  • Node events (NodeCreating, PositionChanged, SizeChanged)
  • Connector events (ConnectionChanged, SegmentChanged)
  • Selection events (SelectionChanged)
  • History change events (HistoryChanged for undo/redo)
  • Event argument types and usage patterns
📄 阅读: references/events.md
  • 图表级事件(Created、Click、Drop)
  • 节点事件(NodeCreating、PositionChanged、SizeChanged)
  • 连接线事件(ConnectionChanged、SegmentChanged)
  • 选择事件(SelectionChanged)
  • 历史记录变更事件(用于撤销/重做的HistoryChanged)
  • 事件参数类型和使用模式

Serialization

序列化

📄 Read: references/serialization.md
  • Saving diagram state as JSON string
  • Loading a diagram from saved JSON
  • Custom serialization properties
  • Partial diagram save and restore patterns
📄 阅读: references/serialization.md
  • 将图表状态保存为JSON字符串
  • 从已保存的JSON加载图表
  • 自定义序列化属性
  • 部分图表保存与恢复模式

Export & Print

导出与打印

📄 Read: references/export-print.md
  • Exporting to PNG, JPEG, SVG formats
  • Export region options (diagram, page, content)
  • Scale and margin settings
  • Print configuration
  • Custom page size and orientation
  • Fit diagram to single page on print
📄 阅读: references/export-print.md
  • 导出为PNG、JPEG、SVG格式
  • 导出区域选项(图表、页面、内容)
  • 缩放和边距设置
  • 打印配置
  • 自定义页面大小和方向
  • 打印时将图表适配到单页

Styling

样式

📄 Read: references/styling.md
  • CSS class customization (
    CssClass
    property)
  • Built-in themes (Material, Bootstrap, Fluent, Tailwind)
  • Node and connector style properties
  • Selection and hover styles
  • Theme Studio customization
  • CSS variable overrides
📄 阅读: references/styling.md
  • CSS类自定义(
    CssClass
    属性)
  • 内置主题(Material、Bootstrap、Fluent、Tailwind)
  • 节点和连接线样式属性
  • 选中和悬停样式
  • 主题工作室自定义
  • CSS变量覆盖

UML Sequence Diagrams

UML序列图

📄 Read: references/uml-sequence.md
  • UML sequence diagram setup
  • Lifelines and activation boxes
  • Message types (synchronous, asynchronous, return, create, destroy)
  • UML interaction shapes and connectors
📄 阅读: references/uml-sequence.md
  • UML序列图设置
  • 生命线和激活框
  • 消息类型(同步、异步、返回、创建、销毁)
  • UML交互形状和连接线

Collaborative Editing

协同编辑

📄 Read: references/collaborative-editing.md
  • Setting up real-time collaborative diagram editing
  • SignalR hub configuration
  • Blazor Server and WASM app integration
  • Handling real-time sync and conflict resolution
📄 阅读: references/collaborative-editing.md
  • 设置实时协同图表编辑
  • SignalR中心配置
  • Blazor Server和WASM应用集成
  • 处理实时同步和冲突解决

Overview Component

概览组件

📄 Read: references/overview-component.md
  • Adding
    SfDiagramOverviewComponent
    as a miniature thumbnail panel
  • Linking the overview to the main diagram via
    SourceID
    /
    ID
  • Controlling panel size with
    Width
    and
    Height
  • Zoom and pan interactions (drag, resize, click, draw-region)
  • Enabling or disabling interactions with
    DiagramOverviewConstraints
  • Required
    @using Syncfusion.Blazor.Diagram.Overview
    namespace.
razor
@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" />
📄 阅读: references/overview-component.md
  • 添加
    SfDiagramOverviewComponent
    作为缩略图面板
  • 通过
    SourceID
    /
    ID
    将概览面板与主图表关联
  • 使用
    Width
    Height
    控制面板大小
  • 缩放和平移交互(拖拽、调整大小、点击、绘制区域)
  • 使用
    DiagramOverviewConstraints
    启用或禁用交互
  • 需要
    @using Syncfusion.Blazor.Diagram.Overview
    命名空间
razor
@using Syncfusion.Blazor.Diagram
@using Syncfusion.Blazor.Diagram.Overview
@using System.Collections.ObjectModel

<SfDiagramComponent ID="element"
                    Width="100%"
                    Height="500px">
</SfDiagramComponent>

<!-- 与上方图表关联的概览面板 -->
<SfDiagramOverviewComponent Height="150px" SourceID="element" />

Advanced Features

高级功能

📄 Read: references/advanced-features.md
  • Context menu (built-in and custom items)
  • Tooltips for nodes, connectors, ports, user handles
  • Gridlines and rulers
  • Scroll settings and page settings
  • Container and group nodes
  • Flip (horizontal/vertical)
  • Constraints (restricting behavior per element)
  • Localization (static text translation)
  • Accessibility (WCAG 2.1, keyboard navigation)
  • Migration from classic to native diagram
📄 阅读: references/advanced-features.md
  • 上下文菜单(内置和自定义项)
  • 节点、连接线、端口、用户操作手柄的工具提示
  • 网格线和标尺
  • 滚动设置和页面设置
  • 容器和组节点
  • 翻转(水平/垂直)
  • 约束(限制元素行为)
  • 本地化(静态文本翻译)
  • 可访问性(WCAG 2.1、键盘导航)
  • 从经典图表迁移到原生图表

Common Mistakes

常见错误

Annotation Editing

注释编辑

⚠️
AllowEditing
does NOT exist
on
ShapeAnnotation
or
PathAnnotation
.
Inline editing is on by default — no property is needed to enable it.
To disable editing, set
Constraints = AnnotationConstraints.ReadOnly
:
csharp
// ❌ 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 }
⚠️
AllowEditing
ShapeAnnotation
PathAnnotation
中不存在

在线编辑默认开启——无需设置任何属性来启用。
禁用编辑,请设置
Constraints = AnnotationConstraints.ReadOnly
csharp
// ❌ 错误 — CS0117: AllowEditing不存在
new ShapeAnnotation { Content = "Label", AllowEditing = false }

// ✅ 正确 — 使用AnnotationConstraints.ReadOnly禁用编辑
new ShapeAnnotation { Content = "Label", Constraints = AnnotationConstraints.ReadOnly }

EndUpdateAsync Method

EndUpdateAsync方法

⚠️ Always use
EndUpdateAsync()
(async) —
EndUpdate()
(sync, non-async) does NOT exist and will cause a compile error.
Use
BeginUpdate()
/
EndUpdateAsync()
when changing multiple properties at once —
await
is required:
csharp
// ❌ Wrong — EndUpdate() does not exist
diagram.BeginUpdate();
// ... changes ...
diagram.EndUpdate();

// ✅ Correct — EndUpdateAsync is async
diagram.BeginUpdate();
// ... changes ...
await diagram.EndUpdateAsync();
⚠️ 请始终使用
EndUpdateAsync()
(异步方法)
EndUpdate()
(同步、非异步方法)不存在,会导致编译错误。
当同时修改多个属性时,请使用
BeginUpdate()
/
EndUpdateAsync()
——必须使用
await
csharp
// ❌ 错误 — EndUpdate()不存在
diagram.BeginUpdate();
// ... 变更操作 ...
diagram.EndUpdate();

// ✅ 正确 — EndUpdateAsync是异步方法
diagram.BeginUpdate();
// ... 变更操作 ...
await diagram.EndUpdateAsync();

Click Event

Click事件

⚠️
ClickEventArgs
name collision:
If your page also uses
@using Syncfusion.Blazor.Navigations
(or Buttons),
ClickEventArgs
becomes ambiguous. Always qualify it:
csharp
// ✅ Use the fully qualified type in the handler signature
private void OnClick(Syncfusion.Blazor.Diagram.ClickEventArgs args) { }
⚠️
args.Count
is NOT an
int
field
— it is a method that returns an
int
.
Do NOT compare it directly with
==
inline 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 */ }
⚠️
ClickEventArgs
命名冲突:
如果你的页面同时使用
@using Syncfusion.Blazor.Navigations
(或Buttons),
ClickEventArgs
会产生歧义。请始终使用完全限定名:
csharp
// ✅ 使用完全限定类型作为处理方法的参数
private void OnClick(Syncfusion.Blazor.Diagram.ClickEventArgs args) { }
⚠️
args.Count
不是
int
字段
— 它是一个返回int的方法
请勿直接使用
==
进行比较,需先存储结果:
csharp
// ❌ 错误 — CS0019: 运算符'=='无法应用于'method group'和'int'类型的操作数
if (args.Count == 2)

// ✅ 正确 — 先存储结果再比较
int clickCount = args.Count;
if (clickCount == 2) { /* 双击 */ }

SizeChanged Event

SizeChanged事件

⚠️
SizeChangedEventArgs.Element
is typed as
DiagramSelectionSettings
, not
Node
.
Pattern-matching
args.Element is Node n
always fails with
CS8121
.
Cast to
DiagramSelectionSettings
and read
.Nodes[0]
to get the resized node:
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;
}
⚠️
args.NewValue.Width
and
args.NewValue.Height
are plain
double
, not
double?
.
Using
??
on them causes
CS0019
. Assign them directly:
csharp
// ❌ Wrong — CS0019
double w = args.NewValue.Width ?? 0;

// ✅ Correct
double w = args.NewValue.Width;
⚠️
SizeChangedEventArgs.Element
的类型是
DiagramSelectionSettings
,而非
Node

使用模式匹配
args.Element is Node n
会因
CS8121
失败。
请将其转换为
DiagramSelectionSettings
并读取
.Nodes[0]
以获取调整大小后的节点:
csharp
// ❌ 错误 — CS8121: DiagramSelectionSettings无法匹配Node
if (args.Element is Node n) { }

// ✅ 正确 — Element是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;
}
⚠️
args.NewValue.Width
args.NewValue.Height
是普通
double
类型
,而非
double?

对它们使用
??
会导致
CS0019
错误。请直接赋值:
csharp
// ❌ 错误 — CS0019
double w = args.NewValue.Width ?? 0;

// ✅ 正确
double w = args.NewValue.Width;

Selection Changed Event

Selection Changed事件

⚠️
SelectionChangedEventArgs
name collision:
If your page also uses
@using Syncfusion.Blazor.Buttons

(or other Syncfusion packages),
SelectionChangedEventArgs
becomes ambiguous. Always qualify it:
csharp
// ✅ Fully qualified
private void OnSelectionChanged(Syncfusion.Blazor.Diagram.SelectionChangedEventArgs args) { }
⚠️
args.NewValue
is a
DiagramSelectionSettings
object — NOT a
Node
, NOT a collection:
  • Pattern-matching
    args.NewValue is Node
    always fails with
    CS8121
  • Iterating
    args.NewValue
    as a collection fails — it is a single settings object
  • The only correct approach is to read
    _diagram.SelectionSettings.Nodes
    /
    .Connectors
    :
csharp
// ❌ 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);
⚠️
SelectionChangedEventArgs
命名冲突:
如果你的页面同时使用
@using Syncfusion.Blazor.Buttons

(或其他Syncfusion包),
SelectionChangedEventArgs
会产生歧义。请始终使用完全限定名:
csharp
// ✅ 使用完全限定名
private void OnSelectionChanged(Syncfusion.Blazor.Diagram.SelectionChangedEventArgs args) { }
⚠️
args.NewValue
DiagramSelectionSettings
对象——不是
Node
,也不是集合:
  • 使用模式匹配
    args.NewValue is Node
    会因
    CS8121
    失败
  • args.NewValue
    作为集合遍历会失败——它是单个设置对象
  • 唯一正确的方法是读取
    _diagram.SelectionSettings.Nodes
    /
    .Connectors
csharp
// ❌ 错误 — CS8121: DiagramSelectionSettings无法匹配Node
if (args.NewValue is Node n) { }

// ❌ 错误 — DiagramSelectionSettings不是可枚举类型
foreach (var item in args.NewValue) { }

// ✅ 正确 — 使用图表实例的SelectionSettings
foreach (var node in _diagram.SelectionSettings.Nodes)
    Console.WriteLine(node.ID);
foreach (var conn in _diagram.SelectionSettings.Connectors)
    Console.WriteLine(conn.ID);

Text Changed Event

Text Changed事件

⚠️
TextChangedEventArgs
does NOT exist
— using it causes
CS0246
.
The correct event args type is
TextChangeEventArgs
(no
d
):
csharp
// ❌ Wrong — CS0246: TextChangedEventArgs not found
private void OnTextChanged(TextChangedEventArgs args) { }

// ✅ Correct
private void OnTextChanged(TextChangeEventArgs args) { }
⚠️
TextChangedEventArgs
不存在
— 使用它会导致
CS0246
错误。
正确的事件参数类型是**
TextChangeEventArgs
**(没有末尾的
d
):
csharp
// ❌ 错误 — CS0246: TextChangedEventArgs未找到
private void OnTextChanged(TextChangedEventArgs args) { }

// ✅ 正确
private void OnTextChanged(TextChangeEventArgs args) { }

Drag Start Event

Drag Start事件

⚠️
DragStartEventArgs
is ambiguous
when
Syncfusion.Blazor.Popups
(or other packages that expose
DragStartEventArgs
) is also referenced.
Always qualify it as
Syncfusion.Blazor.Diagram.DragStartEventArgs
:
csharp
// ❌ Wrong — CS0104: ambiguous reference between Diagram and Popups
private void OnDragStart(DragStartEventArgs args) { }

// ✅ Correct — fully qualified
private void OnDragStart(Syncfusion.Blazor.Diagram.DragStartEventArgs args) { }
⚠️
DragEnterEventArgs
does NOT exist
in
Syncfusion.Blazor.Diagram
.
There is no
DragEnter
event
on
SfDiagramComponent
that receives a
DragEnterEventArgs
.
The available drag events on
SfDiagramComponent
are:
DragStart
,
Dragging
,
DragLeave
,
DragDrop
— all for SymbolPalette drag-and-drop only.
For tracking when a node is being moved (internal drag), use
PositionChanged
:
csharp
// ❌ 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})");
}
⚠️
DragStartEventArgs
存在歧义
当引用
Syncfusion.Blazor.Popups
(或其他暴露
DragStartEventArgs
的包)时。
请始终使用完全限定名
Syncfusion.Blazor.Diagram.DragStartEventArgs
csharp
// ❌ 错误 — CS0104: Diagram和Popups中的DragStartEventArgs存在歧义
private void OnDragStart(DragStartEventArgs args) { }

// ✅ 正确 — 使用完全限定名
private void OnDragStart(Syncfusion.Blazor.Diagram.DragStartEventArgs args) { }
⚠️
DragEnterEventArgs
Syncfusion.Blazor.Diagram
中不存在

SfDiagramComponent
上没有接收
DragEnterEventArgs
DragEnter
事件。
SfDiagramComponent
上可用的拖拽事件包括:
DragStart
Dragging
DragLeave
DragDrop
——这些仅适用于SymbolPalette的拖放操作。
要跟踪节点移动(内部拖拽),请使用
PositionChanged
事件:
csharp
// ❌ 错误 — DragEnterEventArgs不存在
private void OnDragEnter(DragEnterEventArgs args) { }

// ❌ 错误 — SfDiagramComponent上不存在OnPositionChange事件
<SfDiagramComponent OnPositionChange="OnPositionChange" />

// ✅ 正确 — 使用PositionChanged事件
<SfDiagramComponent PositionChanged="OnPositionChanged" />

private void OnPositionChanged(PositionChangedEventArgs args)
{
    if (args.Element is Node n)
        Console.WriteLine($"节点 {n.ID} 移动到 ({n.OffsetX}, {n.OffsetY})");
}

Snap Distance

吸附距离

⚠️
SnapObjectDistance
does NOT exist
on
SnapSettings
— using it causes
InvalidOperationException: does not have a property matching the name 'SnapObjectDistance'
.
The correct property name is
SnapDistance
:
razor
@* ❌ Wrong — SnapObjectDistance does not exist *@
<SnapSettings SnapObjectDistance="5" />

@* ✅ Correct *@
<SnapSettings Constraints="SnapConstraints.SnapToObject" SnapDistance="5" />
⚠️
SnapObjectDistance
SnapSettings
中不存在
— 使用它会导致
InvalidOperationException: 找不到名为'SnapObjectDistance'的属性

正确的属性名是**
SnapDistance
**:
razor
@* ❌ 错误 — SnapObjectDistance不存在 *@
<SnapSettings SnapObjectDistance="5" />

@* ✅ 正确 *@
<SnapSettings Constraints="SnapConstraints.SnapToObject" SnapDistance="5" />

Styling

样式设置

⚠️
CssClass
does NOT exist
on
SfDiagramComponent
— using it causes
InvalidOperationException: Object of type 'SfDiagramComponent' does not have a property matching the name 'CssClass'
.
Wrap the component in a
<div>
with a scoping class instead:
razor
@* ❌ Wrong — CssClass does not exist on SfDiagramComponent *@
<SfDiagramComponent CssClass="my-diagram" />

@* ✅ Correct — use a wrapper div *@
<div class="my-diagram">
    <SfDiagramComponent ... />
</div>
⚠️
CssClass
SfDiagramComponent
中不存在
— 使用它会导致
InvalidOperationException: 类型为'SfDiagramComponent'的对象没有名为'CssClass'的属性

请将组件包裹在带有作用域类的
<div>
中:
razor
@* ❌ 错误 — SfDiagramComponent上不存在CssClass *@
<SfDiagramComponent CssClass="my-diagram" />

@* ✅ 正确 — 使用包裹div *@
<div class="my-diagram">
    <SfDiagramComponent ... />
</div>

Phase Offset Property

阶段偏移属性

⚠️
Phase.Offset
does NOT exist
— using it causes a compile error.
Use
Phase.Width
to set the size of a phase in a swimlane:
csharp
// ❌ Wrong — Offset does not exist on Phase
new Phase { ID = "ph1", Offset = 220 }

// ✅ Correct — use Width
new Phase { ID = "ph1", Width = 220 }
⚠️
Phase.Offset
不存在
— 使用它会导致编译错误。
请使用**
Phase.Width
**来设置泳道中阶段的大小:
csharp
// ❌ 错误 — Phase上不存在Offset
new Phase { ID = "ph1", Offset = 220 }

// ✅ 正确 — 使用Width
new Phase { ID = "ph1", Width = 220 }

Lane Constraints Property

泳道约束属性

⚠️
Lane.Constraints
does NOT exist
and
LaneConstraints
enum does NOT exist
.
Individual lanes cannot have constraints set via a
Constraints
property.
To restrict swimlane-level interactions, use
SwimlaneConstraints
on the
Swimlane
object itself:
csharp
// ❌ 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;
⚠️
Lane.Constraints
不存在,且
LaneConstraints
枚举也不存在

无法通过
Constraints
属性为单个泳道设置约束。
要限制泳道级别的交互,请在**
Swimlane
对象上使用
SwimlaneConstraints
**:
csharp
// ❌ 错误 — Lane.Constraints和LaneConstraints不存在
lane.Constraints = LaneConstraints.Default & ~LaneConstraints.ResizeEntries;

// ✅ 正确 — 在Swimlane对象上设置约束
swimlane.Constraints = SwimlaneConstraints.Default & ~SwimlaneConstraints.Interaction;

FitMode.Page Value

FitMode.Page值

⚠️
FitMode.Page
does NOT exist
— using it causes
CS0117
.
The correct values for
FitMode
are
FitMode.Width
and
FitMode.Height
:
csharp
// ❌ 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 }
⚠️
FitMode.Page
不存在
— 使用它会导致
CS0117
错误。
FitMode
的正确值是**
FitMode.Width
FitMode.Height
**:
csharp
// ❌ 错误 — FitMode.Page不存在
new FitOptions { Mode = FitMode.Page }

// ✅ 正确 — 使用FitMode.Width或FitMode.Height
new FitOptions { Mode = FitMode.Width, Region = DiagramRegion.Content }

LoadDiagram Method

LoadDiagram方法

⚠️
SfDiagramComponent.LoadDiagram()
does NOT exist
— using it causes a compile error.
Use the async version
LoadDiagramAsync()
instead:
csharp
// ❌ Wrong — LoadDiagram() does not exist
diagram.LoadDiagram(savedJson);

// ✅ Correct — use LoadDiagramAsync
await diagram.LoadDiagramAsync(savedJson);
⚠️
SfDiagramComponent.LoadDiagram()
不存在
— 使用它会导致编译错误。
请使用异步版本**
LoadDiagramAsync()
**:
csharp
// ❌ 错误 — LoadDiagram()不存在
diagram.LoadDiagram(savedJson);

// ✅ 正确 — 使用LoadDiagramAsync
await diagram.LoadDiagramAsync(savedJson);

FitToPageAsync Method

FitToPageAsync方法

⚠️
SfDiagramComponent.FitToPageAsync()
does NOT exist
— using it causes a compile error.
Use the non-async overload
FitToPage()
instead:
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 });
⚠️
SfDiagramComponent.FitToPageAsync()
不存在
— 使用它会导致编译错误。
请使用非异步重载**
FitToPage()
**:
csharp
// ❌ 错误 — FitToPageAsync不存在
await diagram.FitToPageAsync(new FitOptions { Mode = FitMode.Width });

// ✅ 正确 — 使用FitToPage(同步方法)
diagram.FitToPage(new FitOptions { Mode = FitMode.Width, Region = DiagramRegion.Content });

BasicShapes Enum

BasicShapes枚举

⚠️
BasicShapes
does NOT exist
— use
NodeBasicShapes
instead:
csharp
// ❌ Wrong
new BasicShape { Shape = BasicShapes.Rectangle }

// ✅ Correct
new BasicShape { Shape = NodeBasicShapes.Rectangle }
⚠️
BasicShapes
不存在
— 请使用
NodeBasicShapes
替代:
csharp
// ❌ 错误
new BasicShape { Shape = BasicShapes.Rectangle }

// ✅ 正确
new BasicShape { Shape = NodeBasicShapes.Rectangle }

DiagramThickness Constructor

DiagramThickness构造函数

⚠️
DiagramThickness
does NOT have a 4-argument constructor
— using it causes
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 }
⚠️
DiagramThickness
没有4参数构造函数
— 使用它会导致
CS1729: 不包含接受4个参数的构造函数

请使用对象初始化器语法和命名属性:
csharp
// ❌ 错误 — CS1729: 没有4参数构造函数
new DiagramThickness(20, 50, 20, 20)

// ✅ 正确 — 使用对象初始化器和命名属性
new DiagramThickness { Left = 20, Top = 50, Right = 20, Bottom = 20 }

// ✅ 正确 — 仅设置需要的边
new DiagramThickness { Top = 50 }

ScrollSettings EnableAutoScroll Property

ScrollSettings EnableAutoScroll属性

⚠️
CanAutoScroll
does NOT exist
on
ScrollSettings
— using it causes
InvalidOperationException: does not have a property matching the name 'CanAutoScroll'
.
The correct property name is
EnableAutoScroll
:
razor
@* ❌ Wrong — CanAutoScroll does not exist *@
<ScrollSettings CanAutoScroll="true" />

@* ✅ Correct *@
<ScrollSettings EnableAutoScroll="true" />
⚠️
CanAutoScroll
ScrollSettings
中不存在
— 使用它会导致
InvalidOperationException: 找不到名为'CanAutoScroll'的属性

正确的属性名是**
EnableAutoScroll
**:
razor
@* ❌ 错误 — CanAutoScroll不存在 *@
<ScrollSettings CanAutoScroll="true" />

@* ✅ 正确 *@
<ScrollSettings EnableAutoScroll="true" />

Zoom, Undo, and Redo Methods

缩放、撤销和重做方法

⚠️
ZoomAsync()
,
UndoAsync()
, and
RedoAsync()
do NOT exist
— using them causes a compile error.
Use the non-async overloads
Zoom()
,
Undo()
, and
Redo()
instead:
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();
⚠️
ZoomAsync()
UndoAsync()
RedoAsync()
不存在
— 使用它们会导致编译错误。
请使用非异步重载**
Zoom()
Undo()
Redo()
**:
csharp
// ❌ 错误 — ZoomAsync、UndoAsync、RedoAsync不存在
await _diagram.ZoomAsync(1.2, new DiagramPoint { X = 300, Y = 300 });
await _diagram.UndoAsync();
await _diagram.RedoAsync();

// ✅ 正确 — 使用非异步重载
_diagram.Zoom(1.2, new DiagramPoint { X = 300, Y = 300 });
_diagram.Undo();
_diagram.Redo();

Overview Component Namespace

概览组件命名空间

⚠️
SfDiagramOverviewComponent
requires an additional
@using
— it lives in
Syncfusion.Blazor.Diagram.Overview
, NOT in
Syncfusion.Blazor.Diagram
. Forgetting it causes
CS0246
:
razor
@* ❌ 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
⚠️
SourceID
must exactly match the
ID
set on
SfDiagramComponent
— the
ID
is NOT auto-generated; you must set it explicitly. A mismatch (including case) renders the overview empty:
razor
@* ❌ 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 nest
SfDiagramOverviewComponent
inside
SfDiagramComponent
— the overview is a sibling component rendered outside the diagram markup.
⚠️
SfDiagramOverviewComponent
需要额外的
@using
— 它位于
Syncfusion.Blazor.Diagram.Overview
中,而非
Syncfusion.Blazor.Diagram
。忘记添加会导致
CS0246
错误:
razor
@* ❌ 错误 — 没有Overview命名空间的话,SfDiagramOverviewComponent无法找到 *@
@using Syncfusion.Blazor.Diagram

@* ✅ 正确 — 需要两个命名空间 *@
@using Syncfusion.Blazor.Diagram
@using Syncfusion.Blazor.Diagram.Overview
⚠️
SourceID
必须与
SfDiagramComponent
上设置的
ID
完全匹配
ID
不会自动生成;你必须显式设置。不匹配(包括大小写)会导致概览面板为空:
razor
@* ❌ 错误 — 图表未设置ID;SourceID没有可关联的对象 *@
<SfDiagramComponent Width="100%" Height="500px" Nodes="@_nodes" />
<SfDiagramOverviewComponent SourceID="myDiagram" Height="150px" />

@* ✅ 正确 — 图表设置了ID,SourceID完全匹配 *@
<SfDiagramComponent ID="myDiagram" Width="100%" Height="500px" Nodes="@_nodes" />
<SfDiagramOverviewComponent SourceID="myDiagram" Height="150px" />
⚠️ 请勿将
SfDiagramOverviewComponent
嵌套在
SfDiagramComponent
内部
— 概览面板是同级组件,需在图表标记外部渲染。