syncfusion-wpf-docx-editor

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Syncfusion WPF DOCX Editor

Syncfusion WPF DOCX 编辑器

Overview

概述

This skill helps developers generate WPF code for integrating the Syncfusion DOCX Editor into their applications. It provides ready-to-use snippets and best practices for embedding a SfRichTextBoxAdv that supports editing, reviewing, formatting, and more.
本技能帮助开发者生成在其应用中集成Syncfusion DOCX编辑器的WPF代码,提供可直接使用的代码片段和嵌入SfRichTextBoxAdv的最佳实践,该组件支持编辑、审阅、格式化等功能。

Key Capabilities

核心功能

  • Document Editing: Create, edit, and view Word documents.
  • Protection: Apply read-only mode, allow comments.
  • Comments: Add comments, replies, and navigate between them.
  • Find and replace: Perform programmatic find and replace operations for automation.
  • Import/Export: Open and save .doc/.docx/.rtf/.html/.xaml/.txt.
  • Clipboard: Copy, cut, paste rich content with formatting.
  • Hyperlinks: Insert, edit, and navigate hyperlinks.
  • 文档编辑:创建、编辑和查看Word文档。
  • 文档保护:应用只读模式、允许添加批注。
  • 批注管理:添加批注、回复批注并在批注间导航。
  • 查找替换:执行程序化的查找和替换操作以实现自动化。
  • 导入/导出:打开和保存.doc/.docx/.rtf/.html/.xaml/.txt格式的文档。
  • 剪贴板操作:复制、剪切、粘贴带有格式的富文本内容。
  • 超链接处理:插入、编辑和导航超链接。

Prerequisites

前置条件

Quick Start Examples

快速入门示例

Example 1: Create Document Editor

示例1:创建文档编辑器

User: "Show me code to create a Document Editor component." Result: A WPF XAML + C# snippet that initializes
SfRichTextBoxAdv
.
用户:"展示创建文档编辑器组件的代码。" **结果:**一段初始化
SfRichTextBoxAdv
的WPF XAML + C#代码片段。

Example 2: Enable Read‑Only Restriction Mode

示例2:启用只读限制模式

User: "Create a Document Editor with Read‑Only restriction mode." Result: A C# snippet that loads a document and applies read-only protection during initialization.

用户:"创建一个带有只读限制模式的文档编辑器。" **结果:**一段在初始化时加载文档并应用只读保护的C#代码片段。

Generate C# Code for the User's Project (default)

为用户项目生成C#代码(默认)

Trigger keywords: "code", "snippet", "how to", "how to write", "show me", "sample", "example code", "generate code", "generate code for", "implement", "implementation", "create", "integrate", "add to component", "add to project", "configure documenteditor", "API example", "usage example", "how do I", "how to use", "document editor", "wpf document editor", "docx editor", "wpf docx editor", "load docx", "comments", "protect document", "find and replace","MainWindow.xaml", "NuGet", "sfrichtextboxadv", "sfrichtextribbon"
Workflow:
  1. Analyze the user's request to identify the feature (e.g., comments, find and replace, import and export).
  2. Read the relevant
    references/*.md
    file(s) to understand the APIs and code patterns for the requested feature.
  3. STOP before generating code. Check if the user has already chosen a delivery mode.
  4. If no delivery mode is chosen yet, you MUST ask the user first using this concise multiple-choice question:
    "How would you like to receive the generated code?"
    • Option 1: Replace the code in a specific project file (you'll need to provide the file path and confirm)
    • Option 2: Share the code directly in the chat window
  5. Only after the user selects a delivery mode, proceed to generate WPF code using the APIs and snippets from
    references/*.md
    , substituting concrete placeholders from the user's project.
  6. Do NOT make changes to workspace project files unless the user explicitly chose Option 1 and provided the file path with permission.
  7. Provide complete WPF snippets and concise integration steps after delivering the code.
Refer to
## Rules
section for operational constraints (output directory, temporary files, allowed libraries, etc.)

触发关键词:"code", "snippet", "how to", "how to write", "show me", "sample", "example code", "generate code", "generate code for", "implement", "implementation", "create", "integrate", "add to component", "add to project", "configure documenteditor", "API example", "usage example", "how do I", "how to use", "document editor", "wpf document editor", "docx editor", "wpf docx editor", "load docx", "comments", "protect document", "find and replace","MainWindow.xaml", "NuGet", "sfrichtextboxadv", "sfrichtextribbon"
工作流程:
  1. 分析用户请求以识别所需功能(例如批注、查找替换、导入导出)。
  2. 阅读相关的
    references/*.md
    文件,了解所需功能对应的API和代码模式。
  3. 生成代码前请暂停。检查用户是否已选择交付模式。
  4. 如果用户尚未选择交付模式,必须先使用以下简洁的选择题询问用户:
    “您希望以何种方式接收生成的代码?”
    • **选项1:**替换特定项目文件中的代码(您需要提供文件路径并确认)
    • **选项2:**直接在聊天窗口中分享代码
  5. 仅在用户选择交付模式后,使用
    references/*.md
    中的API和代码片段生成WPF代码,替换用户项目中的具体占位符。
  6. 除非用户明确选择选项1并提供了经许可的文件路径,否则请勿修改工作区项目文件
  7. 交付代码后,提供完整的WPF代码片段和简洁的集成步骤。
有关操作约束(输出目录、临时文件、允许使用的库等),请参考
## 规则
部分

Code References

代码参考

All code snippets and examples are in the
references/
folder. Each file contains:
  • Minimal React Code — a working, ready-to-use snippet
  • Placeholders — values the user must customize
  • Notes — best practices, additional information to note while using that functionality, constraints
FilePurpose
automatic-suggestion.mdConfigure automatic text suggestions and mentions using the @ character.
background.mdCustomize the background of the document and editor control.
character-format.mdApply character formatting such as font family, size, style, and color.
clipboard.mdPerform copy, cut, and paste operations within the document editor.
commands.mdUse built-in editor commands and configure command bindings.
comments.mdInsert, manage, reply to, navigate and delete document comments.
determine-editing-context-type.mdIdentify the current editing context (text, table, image, etc.).
dialogs.mdUse built-in dialogs and customize their appearance and behavior.
document-editor.mdCreate, initialize, and configure the WPF DOCX Editor.
document-properties.mdAccess document statistics such as word count, page count, and current page.
find-and-replace.mdSearch for text and perform find-and-replace operations.
hyperlink.mdInsert, edit, and manage hyperlinks in documents.
image.mdInsert and manage images in the document.
layout-types.mdSwitch between page layout modes (Pages / Continuous / Blocks).
lists.mdCreate and manage bulleted and numbered lists.
localization.mdApply localization using
.resx
resources and UI culture settings.
lost-focus-behavior.mdKeep the caret and selection highlight visible when the editor loses focus.
minitoolbar.mdEnable and disable the mini toolbar for quick formatting actions.
mvvm.mdIntegrate the document editor with MVVM using data binding and view models.
open-document.mdOpen and load documents from files, streams, and memory using sync and async APIs.
paragraph-format.mdApply paragraph formatting such as alignment, spacing, and indentation.
print.mdPrint document contents and configure print behavior.
save-document.mdSave and export documents to files and streams using sync and async APIs.
section-format.mdConfigure section-level settings such as page size, margins, and headers/footers.
selection.mdWork with text selection APIs, navigation, formatting, and keyboard-based selection.
shapes.mdPreserve and interact with shapes such as text boxes and rectangles from imported documents.
spellchecker.mdEnable spell checking and configure options and custom dictionaries.
styles.mdCreate, apply, modify, and clear character, paragraph, table, and linked styles.
table.mdCreate and manipulate tables including rows, columns, cells, and alignment.
template-and-styling-document-editor.mdCustomize control templates, styles, context menus, panes, and overall editor UI appearance.
undo-redo.mdUndo and redo document editing actions and configure undo behavior.
virtualization.mdEnable UI virtualization and apply performance optimization techniques.

所有代码片段和示例都位于
references/
文件夹中。每个文件包含:
  • 最简WPF代码 — 可直接运行的可用代码片段
  • 占位符 — 用户必须自定义的值
  • 说明 — 使用该功能时的最佳实践、额外注意事项、约束条件
文件用途
automatic-suggestion.md配置自动文本建议和使用@字符的提及功能。
background.md自定义文档和编辑器控件的背景。
character-format.md应用字符格式,如字体族、字号、样式和颜色。
clipboard.md在文档编辑器内执行复制、剪切和粘贴操作。
commands.md使用内置编辑器命令并配置命令绑定。
comments.md插入、管理、回复、导航和删除文档批注。
determine-editing-context-type.md识别当前编辑上下文(文本、表格、图片等)。
dialogs.md使用内置对话框并自定义其外观和行为。
document-editor.md创建、初始化和配置WPF DOCX编辑器。
document-properties.md访问文档统计信息,如字数、页数和当前页码。
find-and-replace.md搜索文本并执行查找和替换操作。
hyperlink.md在文档中插入、编辑和管理超链接。
image.md在文档中插入和管理图片。
layout-types.md在页面布局模式(页面/连续/块)之间切换。
lists.md创建和管理项目符号列表和编号列表。
localization.md使用.resx资源和UI区域设置应用本地化。
lost-focus-behavior.md当编辑器失去焦点时,保持插入符和选中内容高亮可见。
minitoolbar.md启用或禁用用于快速格式化操作的迷你工具栏。
mvvm.md使用数据绑定和视图模型将文档编辑器与MVVM模式集成。
open-document.md使用同步和异步API从文件、流和内存中打开和加载文档。
paragraph-format.md应用段落格式,如对齐方式、间距和缩进。
print.md打印文档内容并配置打印行为。
save-document.md使用同步和异步API将文档保存和导出到文件和流中。
section-format.md配置节级设置,如页面大小、边距和页眉/页脚。
selection.md使用文本选择API、导航、格式化和基于键盘的选择功能。
shapes.md保留并与导入文档中的形状(如文本框、矩形)交互。
spellchecker.md启用拼写检查并配置选项和自定义词典。
styles.md创建、应用、修改和清除字符样式、段落样式、表格样式和链接样式。
table.md创建和操作表格,包括行、列、单元格和对齐方式。
template-and-styling-document-editor.md自定义控件模板、样式、上下文菜单、窗格和编辑器整体UI外观。
undo-redo.md撤销和重做文档编辑操作并配置撤销行为。
virtualization.md启用UI虚拟化并应用性能优化技术。

Key Rules for Code Generation

代码生成核心规则

  1. No inline code in SKILL.md — Always point to snippets in
    references/*.md
    . This file is loaded into context for every prompt; inline code wastes tokens.
  2. Snippets must be tested — All code must build and run against current Syncfusion WPF NuGet packages (e.g., Syncfusion.SfRichTextBoxAdv.WPF) and supported .NET target frameworks.
  3. Minimal Code + Placeholders + Notes — Every reference file must include:
    • Minimal Code (complete, working snippet)
    • Placeholders (values user must substitute — marked with
      {{ }}
      or
      [PLACEHOLDER]
      )
    • Notes (best practices, framework-specific adaptations, constraints)
  4. Share code and notes for the requirement — Never create temporary files or scripts.
  5. License handling — Never hardcode license keys. Point user to environment variables or config files.
  6. Framework adaptation — Default to C# + XAML. When user specifies framework.
  7. No hallucinated APIs — Use only verified Syncfusion DOCX Editor SDK method names. One wrong method breaks user trust.
  1. SKILL.md中禁止内嵌代码 — 始终指向
    references/*.md
    中的代码片段。该文件会加载到每个提示的上下文中,内嵌代码会浪费令牌。
  2. 代码片段必须经过测试 — 所有代码必须能基于当前Syncfusion WPF NuGet包(例如Syncfusion.SfRichTextBoxAdv.WPF)和支持的.NET目标框架构建并运行。
  3. 最简代码 + 占位符 + 说明 — 每个参考文件必须包含:
    • 最简代码(完整、可运行的代码片段)
    • 占位符(用户必须替换的值 — 用
      {{ }}
      [PLACEHOLDER]
      标记)
    • 说明(最佳实践、特定框架适配、约束条件)
  4. 仅分享符合需求的代码和说明 — 切勿创建临时文件或脚本。
  5. 许可证处理 — 切勿硬编码许可证密钥。引导用户使用环境变量或配置文件。
  6. 框架适配 — 默认使用C# + XAML。当用户指定框架时再调整。
  7. 禁止虚构API — 仅使用已验证的Syncfusion DOCX Editor SDK方法名称。一个错误的方法会破坏用户信任。

Rules

规则

  • Only use Syncfusion SfRichTextBoxAdv APIs — never recommend or use alternative Word Editor libraries.
  • No temporary files — never create temporary scripts, intermediate files, or scaffolding outside the output directory
  • C#-only code — all generated code must be valid C# and XAML for WPF projects. No JavaScript, TypeScript, or other languages.
  • 仅使用Syncfusion SfRichTextBoxAdv API — 切勿推荐或使用其他Word编辑器库。
  • 禁止创建临时文件 — 切勿在输出目录外创建临时脚本、中间文件或脚手架。
  • 仅生成C#代码 — 所有生成的代码必须是适用于WPF项目的有效C#和XAML代码。禁止生成JavaScript、TypeScript或其他语言的代码。