syncfusion-blazor-smart-rich-text-editor
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSyncfusion Blazor Smart Rich Text Editor
Syncfusion Blazor 智能富文本编辑器
A comprehensive skill for implementing and configuring the Syncfusion Blazor Smart Rich Text Editor () — an AI-powered WYSIWYG editor that extends the full-featured with intelligent content assistance. Supports OpenAI, Azure OpenAI, Ollama, and custom AI backends. Provides a Smart Action dropdown toolbar, an AI query dialog (), and a fully customizable AI Assistant popup via .
SfSmartRichTextEditorSfRichTextEditorAlt+EnterAssistViewSettings本技能全面介绍如何实现和配置Syncfusion Blazor 智能富文本编辑器()——一款AI驱动的WYSIWYG编辑器,在功能完备的基础上扩展了智能内容辅助能力。支持OpenAI、Azure OpenAI、Ollama及自定义AI后端,提供智能操作下拉工具栏、AI查询对话框(快捷键),并可通过完全自定义AI助手弹窗。
SfSmartRichTextEditorSfRichTextEditorAlt+EnterAssistViewSettingsWhen to Use This Skill
何时使用本技能
Use this skill when the user needs to:
- Install and set up in a Blazor Server or Web App project
SfSmartRichTextEditor - Configure an AI backend: OpenAI, Azure OpenAI, Ollama, or a custom
IChatClient - Register /
IChatInferenceServiceinSyncfusionAIServiceProgram.cs - Use the Smart Action dropdown toolbar for AI commands (summarize, expand, adjust tone)
- Add and
Name = "AI Commands"toName = "AI Query"list to render AI toolbar buttonsToolbarItemModel - Open the AI Query dialog with for free-form AI prompts
Alt+Enter - Configure :
AssistViewSettings,Commands,Suggestions,Prompts,Placeholder, popup sizingMaxPromptHistory - Customize the AI Assistant popup (,
BannerTemplate,HeaderToolbarSettings,PromptToolbarSettings)ResponseToolbarSettings - Handle AI events: ,
AIPromptRequested,AIResponseStopped,AIToolbarItemClicked,AIPopupOpeningAIPopupClosing - Use AI Assistant methods: ,
ShowAIPopupAsync,HideAIPopupAsync,ExecuteAIPromptAsync,UpdateAIResponseAsync,GetAIPromptHistoryAsyncClearAIPromptHistoryAsync - Style or animate the AI Assistant popup ()
.e-rte-aiquery-dialog - Use all inherited features: toolbar, images, tables, events, methods, data binding, paste cleanup, import/export, accessibility
SfRichTextEditor
当用户需要以下操作时,可使用本技能:
- 在Blazor Server或Web App项目中安装并设置
SfSmartRichTextEditor - 配置AI后端:OpenAI、Azure OpenAI、Ollama或自定义
IChatClient - 在中注册
Program.cs/IChatInferenceServiceSyncfusionAIService - 使用智能操作下拉工具栏执行AI命令(总结、扩展、调整语气)
- 在列表中添加
ToolbarItemModel和Name = "AI Commands"以渲染AI工具栏按钮Name = "AI Query" - 使用打开AI查询对话框,输入自由格式的AI提示词
Alt+Enter - 配置:
AssistViewSettings、Commands、Suggestions、Prompts、Placeholder、弹窗尺寸MaxPromptHistory - 自定义AI助手弹窗(、
BannerTemplate、HeaderToolbarSettings、PromptToolbarSettings)ResponseToolbarSettings - 处理AI事件:、
AIPromptRequested、AIResponseStopped、AIToolbarItemClicked、AIPopupOpeningAIPopupClosing - 使用AI助手方法:、
ShowAIPopupAsync、HideAIPopupAsync、ExecuteAIPromptAsync、UpdateAIResponseAsync、GetAIPromptHistoryAsyncClearAIPromptHistoryAsync - 为AI助手弹窗设置样式或动画()
.e-rte-aiquery-dialog - 使用所有继承自的功能:工具栏、图片、表格、事件、方法、数据绑定、粘贴清理、导入/导出、无障碍支持
SfRichTextEditor
Quick Start
快速开始
1. Install NuGet packages:
bash
dotnet add package Syncfusion.Blazor.SmartRichTextEditor
dotnet add package Syncfusion.Blazor.Themes
dotnet add package Microsoft.Extensions.AI
dotnet add package Microsoft.Extensions.AI.OpenAI2. Register services in :
Program.cscsharp
using Syncfusion.Blazor;
using Syncfusion.Blazor.AI;
using Microsoft.Extensions.AI;
using OpenAI;
builder.Services.AddSyncfusionBlazor();
string openAIApiKey = "YOUR_API_KEY";
string openAIModel = "gpt-4";
OpenAIClient openAIClient = new OpenAIClient(openAIApiKey);
IChatClient chatClient = openAIClient.GetChatClient(openAIModel).AsIChatClient();
builder.Services.AddChatClient(chatClient);
builder.Services.AddSingleton<IChatInferenceService, SyncfusionAIService>();3. Add to :
_Imports.razorrazor
@using Syncfusion.Blazor
@using Syncfusion.Blazor.SmartRichTextEditor4. Add CSS/JS in (Server) or (WASM):
App.razorindex.htmlhtml
<link href="_content/Syncfusion.Blazor.Themes/tailwind.css" rel="stylesheet" />
<script src="_content/Syncfusion.Blazor.Core/scripts/syncfusion-blazor.min.js"></script>5. Add the component:
razor
@rendermode InteractiveServer
<SfSmartRichTextEditor>
<h2>Welcome to Smart Rich Text Editor</h2>
<p>Select text and use the Smart Action toolbar, or press Alt+Enter to open the AI Query dialog.</p>
<AssistViewSettings Placeholder="Ask AI to rewrite or generate content." />
</SfSmartRichTextEditor>1. 安装NuGet包:
bash
dotnet add package Syncfusion.Blazor.SmartRichTextEditor
dotnet add package Syncfusion.Blazor.Themes
dotnet add package Microsoft.Extensions.AI
dotnet add package Microsoft.Extensions.AI.OpenAI2. 在中注册服务:
Program.cscsharp
using Syncfusion.Blazor;
using Syncfusion.Blazor.AI;
using Microsoft.Extensions.AI;
using OpenAI;
builder.Services.AddSyncfusionBlazor();
string openAIApiKey = "YOUR_API_KEY";
string openAIModel = "gpt-4";
OpenAIClient openAIClient = new OpenAIClient(openAIApiKey);
IChatClient chatClient = openAIClient.GetChatClient(openAIModel).AsIChatClient();
builder.Services.AddChatClient(chatClient);
builder.Services.AddSingleton<IChatInferenceService, SyncfusionAIService>();3. 添加到:
_Imports.razorrazor
@using Syncfusion.Blazor
@using Syncfusion.Blazor.SmartRichTextEditor4. 在(Server端)或(WASM端)中添加CSS/JS:
App.razorindex.htmlhtml
<link href="_content/Syncfusion.Blazor.Themes/tailwind.css" rel="stylesheet" />
<script src="_content/Syncfusion.Blazor.Core/scripts/syncfusion-blazor.min.js"></script>5. 添加组件:
razor
@rendermode InteractiveServer
<SfSmartRichTextEditor>
<h2>欢迎使用智能富文本编辑器</h2>
<p>选中文本后使用智能操作工具栏,或按Alt+Enter打开AI查询对话框。</p>
<AssistViewSettings Placeholder="请让AI重写或生成内容。" />
</SfSmartRichTextEditor>Navigation Guide
导航指南
Getting Started & AI Service Setup
快速入门与AI服务设置
📄 Read: references/getting-started.md
- NuGet installation: +
Syncfusion.Blazor.SmartRichTextEditorSyncfusion.Blazor.Themes - Full setup for Blazor Server App (Visual Studio and VS Code) and Blazor Web App (.NET 8+)
- OpenAI, Azure OpenAI, Ollama, and custom configuration in
IChatClientProgram.cs - registration pattern for Web App
AddInteractiveServerComponents() - CSS theme and JS script references (.NET 6 through .NET 10)
- Adding the component with
AssistViewSettings - Content retrieval methods (,
GetTextAsync)GetCharCountAsync - Common setup issues and fixes
📄 阅读: references/getting-started.md
- NuGet安装:+
Syncfusion.Blazor.SmartRichTextEditorSyncfusion.Blazor.Themes - Blazor Server App(Visual Studio和VS Code)及Blazor Web App(.NET 8+)的完整设置流程
- 在中配置OpenAI、Azure OpenAI、Ollama及自定义
Program.csIChatClient - Web App的注册模式
AddInteractiveServerComponents() - CSS主题与JS脚本引用(.NET 6至.NET 10)
- 添加带的组件
AssistViewSettings - 内容检索方法(、
GetTextAsync)GetCharCountAsync - 常见设置问题及修复方案
AI Backend Configuration
AI后端配置
📄 Read: references/ai-backends.md
- OpenAI: API key, supported models (,
gpt-4-turbo,gpt-4),gpt-3.5-turbosetup, environment variables and User SecretsOpenAIClient - Azure OpenAI: resource deployment, +
AzureOpenAIClient,ApiKeyCredentialconfig, Managed Identity (production recommended), HIPAA/SOC 2 compliance, monitoring, cost optimizationappsettings.json - Ollama: local model installation (,
mistral),llama2+OllamaApiClientNuGet, Docker Compose, GPU acceleration, model recommendationsOllamaSharp - Custom : implementing
IChatClientfor internal/proprietary AI, registering inIChatClient, streaming responses, retry logic, error handling, corporate AI API exampleProgram.cs
📄 阅读: references/ai-backends.md
- OpenAI:API密钥、支持的模型(、
gpt-4-turbo、gpt-4)、gpt-3.5-turbo设置、环境变量与用户机密OpenAIClient - Azure OpenAI:资源部署、+
AzureOpenAIClient、ApiKeyCredential配置、托管标识(推荐生产环境使用)、HIPAA/SOC 2合规性、监控、成本优化appsettings.json - Ollama:本地模型安装(、
mistral)、llama2+OllamaApiClientNuGet包、Docker Compose、GPU加速、模型推荐OllamaSharp - 自定义:为内部/专有AI实现
IChatClient、在IChatClient中注册、流式响应、重试逻辑、错误处理、企业AI API示例Program.cs
AssistViewSettings — Properties
AssistViewSettings — 属性
📄 Read: references/assist-view-settings.md
- (
Commands): Smart Action dropdown with nested sub-commands and icon CSSList<AICommands> - /
PopupMaxHeight: control popup dimensions (CSS values or pixel numbers)PopupWidth - : placeholder text in the AI prompt textarea
Placeholder - (
Prompts): predefined prompt/response templates loaded into the popupList<AssistViewPrompt> - (
Suggestions): quick suggestion chips shown in the AI popupList<string> - : maximum conversation entries retained (default: 20)
MaxPromptHistory - : custom branding/header
BannerTemplatefor the AI popupRenderFragment - /
HeaderToolbarSettings/PromptToolbarSettings: toolbar customization withResponseToolbarSettingsAssistViewToolbarItem
📄 阅读: references/assist-view-settings.md
- (
Commands):带嵌套子命令和图标CSS的智能操作下拉菜单List<AICommands> - /
PopupMaxHeight:控制弹窗尺寸(CSS值或像素数)PopupWidth - :AI提示文本框中的占位符文本
Placeholder - (
Prompts):加载到弹窗中的预定义提示词/响应模板List<AssistViewPrompt> - (
Suggestions):AI弹窗中显示的快速建议标签List<string> - :保留的最大对话条目数(默认:20)
MaxPromptHistory - :AI弹窗的自定义品牌/页眉
BannerTemplateRenderFragment - /
HeaderToolbarSettings/PromptToolbarSettings:使用ResponseToolbarSettings自定义工具栏AssistViewToolbarItem
AssistViewSettings — Events
AssistViewSettings — 事件
📄 Read: references/ai-events.md
- (
AIPromptRequested): intercept/modify prompt before AI call; setAssistViewPromptRequestedEventArgsto prevent; modifyCancel=true,Response,PromptSuggestionsResponseToolbarItems - (
AIResponseStopped): user clicked "Stop Responding"; providesResponseStoppedEventArgsandDataIndexPrompt - (
AIToolbarItemClicked): handle custom toolbar button clicks; accessAssistViewToolbarItemClickedEventArgs,Item,DataIndex; setEventCancel=true - (
AIPopupOpening): cancel popup opening withBeforeOpenEventArgs; accessargs.Cancel = truereferenceElement - (
AIPopupClosing): cancel popup closing; accessBeforeCloseEventArgs,ClosedBy,IsInteractedPreventFocus
📄 阅读: references/ai-events.md
- (
AIPromptRequested):在调用AI前拦截/修改提示词;设置AssistViewPromptRequestedEventArgs可阻止请求;修改Cancel=true、Response、PromptSuggestionsResponseToolbarItems - (
AIResponseStopped):用户点击“停止响应”;提供ResponseStoppedEventArgs和DataIndexPrompt - (
AIToolbarItemClicked):处理自定义工具栏按钮点击;访问AssistViewToolbarItemClickedEventArgs、Item、DataIndex;设置EventCancel=true - (
AIPopupOpening):设置BeforeOpenEventArgs可取消弹窗打开;访问args.Cancel = true引用Element - (
AIPopupClosing):取消弹窗关闭;访问BeforeCloseEventArgs、ClosedBy、IsInteractedPreventFocus
AssistViewSettings — Methods
AssistViewSettings — 方法
📄 Read: references/ai-methods.md
- : open the AI Assistant popup programmatically
ShowAIPopupAsync() - : close the AI Assistant popup
HideAIPopupAsync() - : send a prompt programmatically (as if user typed it)
ExecuteAIPromptAsync(string prompt) - : stream or inject AI response; set
UpdateAIResponseAsync(string response, bool isFinalUpdate)to hide Stop buttonisFinalUpdate=true - : retrieve all saved prompts/responses as
GetAIPromptHistoryAsync()(chronological, limited toAssistViewPrompt[])MaxPromptHistory - : reset all conversation history
ClearAIPromptHistoryAsync() - Complete example combining all six methods with
@ref
📄 阅读: references/ai-methods.md
- :以编程方式打开AI助手弹窗
ShowAIPopupAsync() - :关闭AI助手弹窗
HideAIPopupAsync() - :以编程方式发送提示词(模拟用户输入)
ExecuteAIPromptAsync(string prompt) - :流式传输或注入AI响应;设置
UpdateAIResponseAsync(string response, bool isFinalUpdate)可隐藏停止按钮isFinalUpdate=true - :以
GetAIPromptHistoryAsync()形式检索所有保存的提示词/响应(按时间顺序,受AssistViewPrompt[]限制)MaxPromptHistory - :重置所有对话历史
ClearAIPromptHistoryAsync() - 结合使用全部六种方法的完整示例
@ref
AI Popup Appearance & CSS
AI弹窗外观与CSS
📄 Read: references/ai-appearance.md
- CSS selectors for the AI popup: ,
.e-rte-aiquery-dialog.e-aiassistview - Customizing popup background, border, box-shadow
- Targeting ,
.e-view-header,.e-view-content .e-toolbarsub-sections for fine-grained control.e-footer - Full custom popup styling example
📄 阅读: references/ai-appearance.md
- AI弹窗的CSS选择器:、
.e-rte-aiquery-dialog.e-aiassistview - 自定义弹窗背景、边框、阴影
- 针对、
.e-view-header、.e-view-content .e-toolbar子区域进行精细化控制.e-footer - 完整的自定义弹窗样式示例
Toolbar Configuration
工具栏配置
📄 Read: references/toolbar.md
- Enabling or disabling the toolbar with
RichTextEditorToolbarSettings.Enable - Toolbar types: Expand, MultiRow, Scrollable, Popup
- Floating toolbar and offset configuration
- Toolbar position (top or bottom)
- Configuring toolbar items with
ToolbarItemModel - Custom toolbar items (template-based)
📄 阅读: references/toolbar.md
- 使用启用或禁用工具栏
RichTextEditorToolbarSettings.Enable - 工具栏类型:展开式、多行式、滚动式、弹出式
- 浮动工具栏与偏移配置
- 工具栏位置(顶部或底部)
- 使用配置工具栏项
ToolbarItemModel - 自定义工具栏项(基于模板)
Built-in Toolbar Tools Reference
内置工具栏工具参考
📄 Read: references/built-in-tools.md
- Default toolbar items for
SfSmartRichTextEditor - AI-specific toolbar items — (Smart Action dropdown) and
Name = "AI Commands"(Ask AI button); must useName = "AI Query"property, NOTNameenumToolbarCommand - Complete list of all enum values
ToolbarCommand - Text formatting, font & styling, alignment, lists, hyperlinks
- Image/table/link quick toolbar item commands using
SfSmartRichTextEditor - Undo/redo, fullscreen, print, source code, preview tools
- Removing or reordering default toolbar items
📄 阅读: references/built-in-tools.md
- 的默认工具栏项
SfSmartRichTextEditor - AI专属工具栏项——(智能操作下拉菜单)和
Name = "AI Commands"(询问AI按钮);必须使用Name = "AI Query"属性,而非Name枚举ToolbarCommand - 所有枚举值的完整列表
ToolbarCommand - 文本格式、字体与样式、对齐方式、列表、超链接
- 使用的图片/表格/链接快速工具栏项命令
SfSmartRichTextEditor - 撤销/重做、全屏、打印、源代码、预览工具
- 删除或重新排序默认工具栏项
Text Formatting
文本格式
📄 Read: references/text-formatting.md
- Bold, italic, underline, strikethrough, subscript, superscript, inline code
- Text alignment (left, center, right, justify)
- Ordered/unordered lists with custom number and bullet styles
- Heading formats (H1–H6, paragraph, blockquote, code)
- Line height configuration
- Horizontal line, format painter, clear format
- Markdown auto-format (inline and block shortcuts)
📄 阅读: references/text-formatting.md
- 加粗、斜体、下划线、删除线、下标、上标、行内代码
- 文本对齐(左对齐、居中、右对齐、两端对齐)
- 有序/无序列表,支持自定义编号和项目符号样式
- 标题格式(H1–H6、段落、块引用、代码块)
- 行高配置
- 水平线、格式刷、清除格式
- Markdown自动格式(行内和块级快捷键)
Images, Video & Audio
图片、视频与音频
📄 Read: references/images-and-media.md
- Image insertion from local machine or URL
- : SaveUrl, Path, AllowedTypes, EnableResize
RichTextEditorImageSettings - Base64 vs server-side upload
- Image quick toolbar configuration
- Video and audio insertion and settings
📄 阅读: references/images-and-media.md
- 从本地机器或URL插入图片
- :SaveUrl、Path、AllowedTypes、EnableResize
RichTextEditorImageSettings - Base64与服务器端上传对比
- 图片快速工具栏配置
- 视频和音频的插入与设置
Tables
表格
📄 Read: references/tables.md
- Creating tables with toolbar item
CreateTable - : width, resize, custom styles
RichTextEditorTableSettings - Table quick toolbar: add/remove rows & columns, merge cells, properties
- Advanced table manipulation (cell selection, split, custom borders)
📄 阅读: references/tables.md
- 使用工具栏项创建表格
CreateTable - :宽度、调整大小、自定义样式
RichTextEditorTableSettings - 表格快速工具栏:添加/删除行和列、合并单元格、属性设置
- 高级表格操作(单元格选择、拆分、自定义边框)
Editor Modes
编辑器模式
📄 Read: references/editor-modes.md
- HTML editor mode (default WYSIWYG)
- Markdown editor mode ()
EditorMode.Markdown - IFrame vs DIV rendering mode
- Source code view toggling
📄 阅读: references/editor-modes.md
- HTML编辑器模式(默认WYSIWYG)
- Markdown编辑器模式()
EditorMode.Markdown - IFrame与DIV渲染模式
- 源代码视图切换
Inline Mode
内联模式
📄 Read: references/inline-mode.md
- Enabling inline toolbar ()
InlineMode - Inline toolbar display on text selection
- Use cases: comment editors, in-place content editing
📄 阅读: references/inline-mode.md
- 启用内联工具栏()
InlineMode - 选中文本时显示内联工具栏
- 使用场景:评论编辑器、原地内容编辑
Custom Tools & Exec Commands
自定义工具与执行命令
📄 Read: references/custom-tools.md
- Adding custom toolbar buttons with and templates
ToolbarItemModel - Executing commands programmatically with
ExecuteCommandAsync - Slash commands (trigger menu) configuration
/ - Format painter advanced settings ()
RichTextEditorFormatPainterSettings
📄 阅读: references/custom-tools.md
- 使用和模板添加自定义工具栏按钮
ToolbarItemModel - 以编程方式使用执行命令
ExecuteCommandAsync - 斜杠命令(触发菜单)配置
/ - 格式刷高级设置()
RichTextEditorFormatPainterSettings
Events (RTE)
事件(RTE)
📄 Read: references/events.md
- child component usage and wiring pattern
RichTextEditorEvents - Lifecycle events: ,
CreatedDestroyed - Focus/interaction: ,
Focus,Blur,OnToolbarClickSelectionChanged - Content events: ,
ValueChange,BeforePasteCleanupAfterPasteCleanup - Toolbar lifecycle: ,
OnActionBeginOnActionComplete - Dialog events: ,
OnDialogOpen,DialogOpened,OnDialogCloseDialogClosed - Quick toolbar: ,
OnQuickToolbarOpen,QuickToolbarOpenedQuickToolbarClosed - Image events: ,
OnImageSelected,BeforeUploadImage,OnImageUploadSuccess,OnImageUploadFailed,ImageUploadChange,OnImageDropImageDelete - Media events: ,
FileSelected,FileUploading,FileUploadSuccess,FileUploadFailed,FileUploadChange,OnMediaDropMediaDeleted - Resize events: ,
OnResizeStartOnResizeStop - Toolbar status:
UpdatedToolbarStatus - Export events: ,
OnExportOnExportFailure - Slash menu:
SlashMenuItemSelecting - Complete EventArgs class reference with all properties
📄 阅读: references/events.md
- 子组件的使用和绑定模式
RichTextEditorEvents - 生命周期事件:、
CreatedDestroyed - 焦点/交互事件:、
Focus、Blur、OnToolbarClickSelectionChanged - 内容事件:、
ValueChange、BeforePasteCleanupAfterPasteCleanup - 工具栏生命周期事件:、
OnActionBeginOnActionComplete - 对话框事件:、
OnDialogOpen、DialogOpened、OnDialogCloseDialogClosed - 快速工具栏事件:、
OnQuickToolbarOpen、QuickToolbarOpenedQuickToolbarClosed - 图片事件:、
OnImageSelected、BeforeUploadImage、OnImageUploadSuccess、OnImageUploadFailed、ImageUploadChange、OnImageDropImageDelete - 媒体事件:、
FileSelected、FileUploading、FileUploadSuccess、FileUploadFailed、FileUploadChange、OnMediaDropMediaDeleted - 调整大小事件:、
OnResizeStartOnResizeStop - 工具栏状态事件:
UpdatedToolbarStatus - 导出事件:、
OnExportOnExportFailure - 斜杠菜单事件:
SlashMenuItemSelecting - 包含所有属性的完整EventArgs类参考
Methods (RTE)
方法(RTE)
📄 Read: references/methods.md
- Focus & selection: ,
FocusAsync,FocusOutAsync,SaveSelectionAsync,RestoreSelectionAsync,SelectAllAsyncGetSelectionAsync - Content retrieval: ,
GetTextAsync,GetSelectedHtmlAsync,GetCharCountAsyncGetXhtmlAsync - Command execution: all overloads with typed args (image, link, table, video, audio, code block, format painter)
ExecuteCommandAsync - Toolbar control: ,
EnableToolbarItem,DisableToolbarItemRemoveToolbarItem - Dialog & UI control: ,
ShowDialogAsync,CloseDialogAsync,ShowFullScreenAsync,PrintAsync,RefreshUIAsyncShowSourceCodeAsync - Undo/redo:
ClearUndoRedoAsync - Full ,
CommandName, andToolbarCommandenum referencesDialogType
📄 阅读: references/methods.md
- 焦点与选择:、
FocusAsync、FocusOutAsync、SaveSelectionAsync、RestoreSelectionAsync、SelectAllAsyncGetSelectionAsync - 内容检索:、
GetTextAsync、GetSelectedHtmlAsync、GetCharCountAsyncGetXhtmlAsync - 命令执行:所有带类型参数的重载(图片、链接、表格、视频、音频、代码块、格式刷)
ExecuteCommandAsync - 工具栏控制:、
EnableToolbarItem、DisableToolbarItemRemoveToolbarItem - 对话框与UI控制:、
ShowDialogAsync、CloseDialogAsync、ShowFullScreenAsync、PrintAsync、RefreshUIAsyncShowSourceCodeAsync - 撤销/重做:
ClearUndoRedoAsync - 完整的、
CommandName和ToolbarCommand枚举参考DialogType
Properties (RTE)
属性(RTE)
📄 Read: references/properties.md
- Content & value: ,
Value,Placeholder,Readonly,Enabled,MaxLengthShowCharCount - Editor behaviour: ,
EditorMode,EnterKey,ShiftEnterKey,EnableTabKey,EnableAutoUrl,EnableMarkdownAutoFormat,EnableClipboardCleanup,EnableXhtml,EnableHtmlEncodeEnableResize - Appearance & layout: ,
Height,Width,CssClass,ShowTooltipFloatingToolbarOffset - IFrame mode: child component with
RichTextEditorIFrameSettings,Enable,AttributesResources - Security & sanitization: ,
EnableHtmlSanitizer,AdditionalSanitizeAttributes,AdditionalSanitizeTagsDeniedSanitizeSelectors - Keyboard & shortcuts: with full
KeyConfiguredefault bindings tableShortcutKeys - Persistence & auto-save: ,
EnablePersistence,SaveIntervalAutoSaveOnIdle - Undo/redo config: ,
UndoRedoStepsUndoRedoTimer - HTTP integration:
HttpClientInstance - Full 38-property summary table
📄 阅读: references/properties.md
- 内容与值:、
Value、Placeholder、Readonly、Enabled、MaxLengthShowCharCount - 编辑器行为:、
EditorMode、EnterKey、ShiftEnterKey、EnableTabKey、EnableAutoUrl、EnableMarkdownAutoFormat、EnableClipboardCleanup、EnableXhtml、EnableHtmlEncodeEnableResize - 外观与布局:、
Height、Width、CssClass、ShowTooltipFloatingToolbarOffset - IFrame模式:子组件,包含
RichTextEditorIFrameSettings、Enable、AttributesResources - 安全与清理:、
EnableHtmlSanitizer、AdditionalSanitizeAttributes、AdditionalSanitizeTagsDeniedSanitizeSelectors - 键盘与快捷键:,包含完整的
KeyConfigure默认绑定表ShortcutKeys - 持久化与自动保存:、
EnablePersistence、SaveIntervalAutoSaveOnIdle - 撤销/重做配置:、
UndoRedoStepsUndoRedoTimer - HTTP集成:
HttpClientInstance - 包含38个属性的完整汇总表
Data Binding & Value Management
数据绑定与值管理
📄 Read: references/data-binding.md
- Two-way binding with
@bind-Value - One-way binding and programmatic value updates
- event for detecting edits
ValueChange - Read-only mode (property)
Readonly - Max length enforcement and character count display
📄 阅读: references/data-binding.md
- 使用进行双向绑定
@bind-Value - 单向绑定与编程式值更新
- 使用事件检测编辑操作
ValueChange - 只读模式(属性)
Readonly - 最大长度限制与字符计数显示
Paste Cleanup
粘贴清理
📄 Read: references/paste-and-cleanup.md
- configuration
RichTextEditorPasteCleanupSettings - Stripping/keeping specific HTML attributes and styles on paste
- Forcing plain text paste
- Enter key behavior (,
EnterKey)ShiftEnterKey - Undo/redo manager configuration
📄 阅读: references/paste-and-cleanup.md
- 配置
RichTextEditorPasteCleanupSettings - 粘贴时剥离/保留特定HTML属性和样式
- 强制粘贴纯文本
- 回车键行为(、
EnterKey)ShiftEnterKey - 撤销/重做管理器配置
Import & Export
导入与导出
📄 Read: references/import-export.md
- Importing Word documents into the editor
- Exporting content to Word (.docx) and PDF
- HTTP client configuration for import/export services
- Mail merge with dynamic data
- WebAssembly performance optimizations for large documents
📄 阅读: references/import-export.md
- 将Word文档导入编辑器
- 将内容导出为Word(.docx)和PDF格式
- 导入/导出服务的HTTP客户端配置
- 动态数据邮件合并
- WebAssembly针对大文档的性能优化
Accessibility & Globalization
无障碍支持与全球化
📄 Read: references/accessibility-globalization.md
- WCAG 2.1 compliance details
- Keyboard shortcuts and navigation reference
- ARIA roles and screen reader support
- RTL layout ()
EnableRtl - Localization and culture configuration
- XHTML validation
📄 阅读: references/accessibility-globalization.md
- WCAG 2.1合规细节
- 键盘快捷键与导航参考
- ARIA角色与屏幕阅读器支持
- RTL布局()
EnableRtl - 本地化与文化配置
- XHTML验证
Common Patterns
常见模式
Basic Smart Rich Text Editor with AI
基础AI智能富文本编辑器
razor
@rendermode InteractiveServer
@using Syncfusion.Blazor.SmartRichTextEditor
<SfSmartRichTextEditor @bind-Value="@Content">
<AssistViewSettings Placeholder="Ask AI to rewrite or generate content." />
</SfSmartRichTextEditor>
@code {
private string Content { get; set; } = "<p>Start editing...</p>";
}razor
@rendermode InteractiveServer
@using Syncfusion.Blazor.SmartRichTextEditor
<SfSmartRichTextEditor @bind-Value="@Content">
<AssistViewSettings Placeholder="请让AI重写或生成内容。" />
</SfSmartRichTextEditor>
@code {
private string Content { get; set; } = "<p>开始编辑...</p>";
}AI with custom Smart Action commands
带自定义智能操作命令的AI编辑器
razor
<SfSmartRichTextEditor>
<AssistViewSettings Commands="@MyCommands" Suggestions="@QuickSuggestions" />
</SfSmartRichTextEditor>
@code {
private List<AICommands> MyCommands = new()
{
new AICommands { Text = "Summarize", Prompt = "Summarize this content concisely" },
new AICommands { Text = "Expand", Prompt = "Add more details and examples" },
new AICommands
{
Text = "Translate",
Items = new List<AICommands>
{
new AICommands { Text = "To French", Prompt = "Translate to French" },
new AICommands { Text = "To Spanish", Prompt = "Translate to Spanish" }
}
}
};
private List<string> QuickSuggestions = new()
{
"Fix grammar", "Make shorter", "More formal", "Simplify"
};
}razor
<SfSmartRichTextEditor>
<AssistViewSettings Commands="@MyCommands" Suggestions="@QuickSuggestions" />
</SfSmartRichTextEditor>
@code {
private List<AICommands> MyCommands = new()
{
new AICommands { Text = "总结", Prompt = "简要总结此内容" },
new AICommands { Text = "扩展", Prompt = "添加更多细节和示例" },
new AICommands
{
Text = "翻译",
Items = new List<AICommands>
{
new AICommands { Text = "翻译成法语", Prompt = "Translate to French" },
new AICommands { Text = "翻译成西班牙语", Prompt = "Translate to Spanish" }
}
}
};
private List<string> QuickSuggestions = new()
{
"修正语法", "缩短文本", "更正式", "简化表达"
};
}Programmatic AI popup control
编程式控制AI弹窗
razor
<SfSmartRichTextEditor>
<AssistViewSettings @ref="AssistViewRef" MaxPromptHistory="10" />
</SfSmartRichTextEditor>
<button @onclick="OpenAI">Open AI</button>
<button @onclick="RunPrompt">Run Prompt</button>
@code {
private AssistViewSettings AssistViewRef;
private async Task OpenAI() =>
await AssistViewRef.ShowAIPopupAsync();
private async Task RunPrompt() =>
await AssistViewRef.ExecuteAIPromptAsync("Improve the clarity of this text");
}razor
<SfSmartRichTextEditor>
<AssistViewSettings @ref="AssistViewRef" MaxPromptHistory="10" />
</SfSmartRichTextEditor>
<button @onclick="OpenAI">打开AI</button>
<button @onclick="RunPrompt">执行提示词</button>
@code {
private AssistViewSettings AssistViewRef;
private async Task OpenAI() =>
await AssistViewRef.ShowAIPopupAsync();
private async Task RunPrompt() =>
await AssistViewRef.ExecuteAIPromptAsync("提升文本清晰度");
}Two-way bound editor with character count
带字符计数的双向绑定编辑器
razor
<SfSmartRichTextEditor @bind-Value="@HtmlContent" ShowCharCount="true" MaxLength="2000">
<AssistViewSettings Placeholder="Ask AI for writing help." />
</SfSmartRichTextEditor>
@code {
private string HtmlContent { get; set; } = string.Empty;
}razor
<SfSmartRichTextEditor @bind-Value="@HtmlContent" ShowCharCount="true" MaxLength="2000">
<AssistViewSettings Placeholder="请让AI协助写作。" />
</SfSmartRichTextEditor>
@code {
private string HtmlContent { get; set; } = string.Empty;
}Read-only display
只读显示模式
razor
<SfSmartRichTextEditor Value="@HtmlContent" Readonly="true">
<RichTextEditorToolbarSettings Enable="false" />
</SfSmartRichTextEditor>razor
<SfSmartRichTextEditor Value="@HtmlContent" Readonly="true">
<RichTextEditorToolbarSettings Enable="false" />
</SfSmartRichTextEditor>Markdown editor mode
Markdown编辑器模式
razor
<SfSmartRichTextEditor EditorMode="EditorMode.Markdown" @bind-Value="@MarkdownContent">
<AssistViewSettings Placeholder="Ask AI to help with your Markdown content." />
</SfSmartRichTextEditor>
@code {
private string MarkdownContent { get; set; } = "**Hello** world!";
}razor
<SfSmartRichTextEditor EditorMode="EditorMode.Markdown" @bind-Value="@MarkdownContent">
<AssistViewSettings Placeholder="请让AI协助处理Markdown内容。" />
</SfSmartRichTextEditor>
@code {
private string MarkdownContent { get; set; } = "**Hello** world!";
}Handle AI prompt event to intercept requests
处理AI提示词事件以拦截请求
razor
<SfSmartRichTextEditor>
<AssistViewSettings AIPromptRequested="OnAIPrompt" />
</SfSmartRichTextEditor>
@code {
private async Task OnAIPrompt(AssistViewPromptRequestedEventArgs args)
{
// Log, validate, or modify args.Prompt before it is sent to AI
Console.WriteLine($"Prompt: {args.Prompt}");
// To cancel: args.Cancel = true;
}
}razor
<SfSmartRichTextEditor>
<AssistViewSettings AIPromptRequested="OnAIPrompt" />
</SfSmartRichTextEditor>
@code {
private async Task OnAIPrompt(AssistViewPromptRequestedEventArgs args)
{
// 在发送至AI前记录、验证或修改args.Prompt
Console.WriteLine($"提示词: {args.Prompt}");
// 如需取消请求:args.Cancel = true;
}
}