syncfusion-blazor-diagram
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseImplementing 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 , nodes, connectors, or shapes
SfDiagramComponent - 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 () 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.
references/*.md必须验证API:在生成代码示例之前,请务必通过参考文件()验证API类名、属性和签名。请勿假设或推断类名。
⚠️ 在编写任何代码之前,请直接查看下方的常见错误部分,避免使用已知的无效API和属性。
references/*.mdQuick 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
常见模式
| 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 |
| 目标 | 参考文档 |
|---|---|
| 首个图表设置 | 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)
- — scroll viewport to show a region
BringIntoView(DiagramRect) - — scroll viewport to center a region
BringIntoCenter(DiagramRect) - — fit content to viewport (sync;
FitToPage(FitOptions?),FitMode.Width/Height/Both)DiagramRegion.Content/PageSettings - — move selected elements by pixels; default 1px;
Nudge(Direction, int?)Direction.Top/Bottom/Left/Right - Z-Order: ,
BringToFront(),BringForward(),SendBackward()— mustSendToBack()firstSelect() - Keyboard shortcuts (built-in table) and (custom/override shortcuts via child component)
CommandManager - uses
CommandManager+KeyboardCommand(KeyGesture+DiagramKeys) +ModifierKeysCommandKeyArgs - Snapping to grid or objects
- Alignment, spacing, and sizing commands (,
SetAlign,SetDistribute— all sync)SetSameSize - User handles (custom action buttons on selection)
- Undo/redo (,
Undo()— sync)Redo()
📄 阅读: references/interaction.md
- 选择模式(单选、多选、框选)
- 拖拽、调整大小和旋转元素
- 缩放和平移(鼠标滚轮、工具栏、程序化操作)
- — 滚动视口以显示指定区域
BringIntoView(DiagramRect) - — 滚动视口以将指定区域居中
BringIntoCenter(DiagramRect) - — 将内容适配到视口(同步操作;
FitToPage(FitOptions?),FitMode.Width/Height/Both)DiagramRegion.Content/PageSettings - — 按像素移动选中元素;默认1px;
Nudge(Direction, int?)Direction.Top/Bottom/Left/Right - 层级顺序:、
BringToFront()、BringForward()、SendBackward()— 必须先执行SendToBack()Select() - 键盘快捷键(内置表格)和(通过子组件自定义/覆盖快捷键)
CommandManager - 使用
CommandManager+KeyboardCommand(KeyGesture+DiagramKeys) +ModifierKeysCommandKeyArgs - 对齐到网格或对象
- 对齐、间距和大小调整命令(、
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 (property)
CssClass - 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 as a miniature thumbnail panel
SfDiagramOverviewComponent - Linking the overview to the main diagram via /
SourceIDID - Controlling panel size with and
WidthHeight - Zoom and pan interactions (drag, resize, click, draw-region)
- Enabling or disabling interactions with
DiagramOverviewConstraints - Required namespace.
@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>
<!-- 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
注释编辑
⚠️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 }
⚠️在AllowEditing或ShapeAnnotation中不存在PathAnnotation
在线编辑默认开启——无需设置任何属性来启用。
要禁用编辑,请设置:Constraints = AnnotationConstraints.ReadOnlycsharp// ❌ 错误 — CS0117: AllowEditing不存在 new ShapeAnnotation { Content = "Label", AllowEditing = false } // ✅ 正确 — 使用AnnotationConstraints.ReadOnly禁用编辑 new ShapeAnnotation { Content = "Label", Constraints = AnnotationConstraints.ReadOnly }
EndUpdateAsync Method
EndUpdateAsync方法
⚠️ 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();
⚠️ 请始终使用(异步方法) —EndUpdateAsync()(同步、非异步方法)不存在,会导致编译错误。EndUpdate()
当同时修改多个属性时,请使用/BeginUpdate()——必须使用EndUpdateAsync():awaitcsharp// ❌ 错误 — EndUpdate()不存在 diagram.BeginUpdate(); // ... 变更操作 ... diagram.EndUpdate(); // ✅ 正确 — EndUpdateAsync是异步方法 diagram.BeginUpdate(); // ... 变更操作 ... await diagram.EndUpdateAsync();
Click Event
Click事件
⚠️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 */ }
⚠️命名冲突: 如果你的页面同时使用ClickEventArgs(或Buttons),@using Syncfusion.Blazor.Navigations
会产生歧义。请始终使用完全限定名:ClickEventArgscsharp// ✅ 使用完全限定类型作为处理方法的参数 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事件
⚠️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;
⚠️的类型是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?
对它们使用会导致??错误。请直接赋值:CS0019csharp// ❌ 错误 — CS0019 double w = args.NewValue.Width ?? 0; // ✅ 正确 double w = args.NewValue.Width;
Selection Changed Event
Selection Changed事件
⚠️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);
⚠️命名冲突: 如果你的页面同时使用SelectionChangedEventArgs@using Syncfusion.Blazor.Buttons
(或其他Syncfusion包),会产生歧义。请始终使用完全限定名:SelectionChangedEventArgscsharp// ✅ 使用完全限定名 private void OnSelectionChanged(Syncfusion.Blazor.Diagram.SelectionChangedEventArgs args) { }
⚠️是args.NewValue对象——不是DiagramSelectionSettings,也不是集合:Node
- 使用模式匹配
会因args.NewValue is Node失败CS8121- 将
作为集合遍历会失败——它是单个设置对象args.NewValue- 唯一正确的方法是读取
/_diagram.SelectionSettings.Nodes:.Connectorscsharp// ❌ 错误 — 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事件
⚠️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) { }
⚠️不存在 — 使用它会导致TextChangedEventArgs错误。CS0246
正确的事件参数类型是****(没有末尾的TextChangeEventArgs):dcsharp// ❌ 错误 — CS0246: TextChangedEventArgs未找到 private void OnTextChanged(TextChangedEventArgs args) { } // ✅ 正确 private void OnTextChanged(TextChangeEventArgs args) { }
Drag Start Event
Drag Start事件
⚠️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})"); }
⚠️存在歧义 当引用DragStartEventArgs(或其他暴露Syncfusion.Blazor.Popups的包)时。DragStartEventArgs
请始终使用完全限定名:Syncfusion.Blazor.Diagram.DragStartEventArgscsharp// ❌ 错误 — 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——这些仅适用于SymbolPalette的拖放操作。DragDrop
要跟踪节点移动(内部拖拽),请使用事件:PositionChangedcsharp// ❌ 错误 — 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
吸附距离
⚠️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" />
⚠️在SnapObjectDistance中不存在 — 使用它会导致SnapSettings。InvalidOperationException: 找不到名为'SnapObjectDistance'的属性
正确的属性名是****:SnapDistancerazor@* ❌ 错误 — SnapObjectDistance不存在 *@ <SnapSettings SnapObjectDistance="5" /> @* ✅ 正确 *@ <SnapSettings Constraints="SnapConstraints.SnapToObject" SnapDistance="5" />
Styling
样式设置
⚠️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>
⚠️在CssClass中不存在 — 使用它会导致SfDiagramComponent
。InvalidOperationException: 类型为'SfDiagramComponent'的对象没有名为'CssClass'的属性
请将组件包裹在带有作用域类的中:<div>razor@* ❌ 错误 — SfDiagramComponent上不存在CssClass *@ <SfDiagramComponent CssClass="my-diagram" /> @* ✅ 正确 — 使用包裹div *@ <div class="my-diagram"> <SfDiagramComponent ... /> </div>
Phase Offset Property
阶段偏移属性
⚠️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 }
⚠️不存在 — 使用它会导致编译错误。Phase.Offset
请使用****来设置泳道中阶段的大小:Phase.Widthcsharp// ❌ 错误 — Phase上不存在Offset new Phase { ID = "ph1", Offset = 220 } // ✅ 正确 — 使用Width new Phase { ID = "ph1", Width = 220 }
Lane Constraints Property
泳道约束属性
⚠️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;
⚠️不存在,且Lane.Constraints枚举也不存在LaneConstraints
无法通过属性为单个泳道设置约束。Constraints
要限制泳道级别的交互,请在**对象上使用Swimlane**:SwimlaneConstraintscsharp// ❌ 错误 — Lane.Constraints和LaneConstraints不存在 lane.Constraints = LaneConstraints.Default & ~LaneConstraints.ResizeEntries; // ✅ 正确 — 在Swimlane对象上设置约束 swimlane.Constraints = SwimlaneConstraints.Default & ~SwimlaneConstraints.Interaction;
FitMode.Page Value
FitMode.Page值
⚠️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 }
⚠️不存在 — 使用它会导致FitMode.Page错误。CS0117
的正确值是**FitMode和FitMode.Width**:FitMode.Heightcsharp// ❌ 错误 — FitMode.Page不存在 new FitOptions { Mode = FitMode.Page } // ✅ 正确 — 使用FitMode.Width或FitMode.Height new FitOptions { Mode = FitMode.Width, Region = DiagramRegion.Content }
LoadDiagram Method
LoadDiagram方法
⚠️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);
⚠️不存在 — 使用它会导致编译错误。SfDiagramComponent.LoadDiagram()
请使用异步版本****:LoadDiagramAsync()csharp// ❌ 错误 — LoadDiagram()不存在 diagram.LoadDiagram(savedJson); // ✅ 正确 — 使用LoadDiagramAsync await diagram.LoadDiagramAsync(savedJson);
FitToPageAsync Method
FitToPageAsync方法
⚠️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 });
⚠️不存在 — 使用它会导致编译错误。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枚举
⚠️does NOT exist — useBasicShapesinstead:NodeBasicShapescsharp// ❌ Wrong new BasicShape { Shape = BasicShapes.Rectangle } // ✅ Correct new BasicShape { Shape = NodeBasicShapes.Rectangle }
⚠️不存在 — 请使用BasicShapes替代:NodeBasicShapescsharp// ❌ 错误 new BasicShape { Shape = BasicShapes.Rectangle } // ✅ 正确 new BasicShape { Shape = NodeBasicShapes.Rectangle }
DiagramThickness Constructor
DiagramThickness构造函数
⚠️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 }
⚠️没有4参数构造函数 — 使用它会导致DiagramThickness。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属性
⚠️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" />
⚠️在CanAutoScroll中不存在 — 使用它会导致ScrollSettings。InvalidOperationException: 找不到名为'CanAutoScroll'的属性
正确的属性名是****:EnableAutoScrollrazor@* ❌ 错误 — CanAutoScroll不存在 *@ <ScrollSettings CanAutoScroll="true" /> @* ✅ 正确 *@ <ScrollSettings EnableAutoScroll="true" />
Zoom, Undo, and Redo Methods
缩放、撤销和重做方法
⚠️,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();
⚠️、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
概览组件命名空间
⚠️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
⚠️需要额外的SfDiagramOverviewComponent— 它位于@using中,而非Syncfusion.Blazor.Diagram.Overview。忘记添加会导致Syncfusion.Blazor.Diagram错误:CS0246razor@* ❌ 错误 — 没有Overview命名空间的话,SfDiagramOverviewComponent无法找到 *@ @using Syncfusion.Blazor.Diagram @* ✅ 正确 — 需要两个命名空间 *@ @using Syncfusion.Blazor.Diagram @using Syncfusion.Blazor.Diagram.Overview
⚠️必须与SourceID上设置的SfDiagramComponent完全匹配 —ID不会自动生成;你必须显式设置。不匹配(包括大小写)会导致概览面板为空:IDrazor@* ❌ 错误 — 图表未设置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