syncfusion-wpf-spellchecker
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseImplementing Syncfusion WPF SpellChecker
实现Syncfusion WPF SpellChecker
SfSpellChecker provides a simple and intuitive interface to check for spelling errors in WPF text editor controls. It offers suggestions for misspelled words through dialog and context menu, supports multiple languages/cultures, custom dictionaries, and various ignore options.
SfSpellChecker为WPF文本编辑器控件提供了简单直观的拼写错误检查界面。它通过对话框和上下文菜单为拼写错误的单词提供建议,支持多语言/区域、自定义词典以及多种忽略选项。
When to Use This Skill
何时使用此技能
Use this skill when you need to:
- Add spell checking capability to WPF TextBox, RichTextBox, or other text editor controls
- Implement dialog-based or context menu-based spell checking
- Support multiple languages and cultures in spell checking
- Add custom dictionaries (Hunspell, Ispell, or OpenOffice formats)
- Configure ignore rules for emails, URLs, HTML tags, mixed case words, etc.
- Provide real-time spelling suggestions to users
- Customize spell checker appearance with themes
- Handle spell check completion events
当你需要以下功能时,可使用此技能:
- 为WPF TextBox、RichTextBox或其他文本编辑器控件添加拼写检查功能
- 实现基于对话框或上下文菜单的拼写检查
- 在拼写检查中支持多语言和区域
- 添加自定义词典(Hunspell、Ispell或OpenOffice格式)
- 配置对电子邮件、URL、HTML标签、大小写混合单词等内容的忽略规则
- 为用户提供实时拼写建议
- 通过主题自定义拼写检查器的外观
- 处理拼写检查完成事件
Component Overview
组件概述
Control: SfSpellChecker (Syncfusion.Windows.Controls.SfSpellChecker)
Platform: WPF
Namespace:
Assembly:
Platform: WPF
Namespace:
Syncfusion.Windows.ControlsAssembly:
Syncfusion.SfSpellChecker.WPFKey Capabilities:
- Dialog-based spell checking with suggestion list
- Context menu suggestions with right-click on error words
- Multi-language support with custom dictionaries
- Ignore options for special text patterns
- Custom word dictionary support
- Real-time error highlighting
- Replace, Ignore All, Add to Dictionary actions
控件: SfSpellChecker (Syncfusion.Windows.Controls.SfSpellChecker)
平台: WPF
命名空间:
程序集:
平台: WPF
命名空间:
Syncfusion.Windows.Controls程序集:
Syncfusion.SfSpellChecker.WPF核心功能:
- 带建议列表的对话框式拼写检查
- 右键点击错误单词显示上下文菜单建议
- 支持多语言及自定义词典
- 特殊文本模式的忽略选项
- 自定义单词词典支持
- 实时错误高亮
- 替换、全部忽略、添加到词典操作
Documentation and Navigation Guide
文档与导航指南
Getting Started
快速入门
📄 Read: references/getting-started.md
- Installation and assembly deployment
- Adding SfSpellChecker to an application
- Attaching spell checker to TextBox
- First spell check with dialog
- Context menu setup
- Enable/disable spell checking
- Getting suggestions programmatically
📄 阅读: references/getting-started.md
- 安装和程序集部署
- 向应用中添加SfSpellChecker
- 将拼写检查器附加到TextBox
- 使用对话框进行首次拼写检查
- 上下文菜单设置
- 启用/禁用拼写检查
- 以编程方式获取建议
Spell Check Methods
拼写检查方法
📄 Read: references/spell-check-methods.md
- Dialog-based spell checking
- Context menu-based suggestions
- PerformSpellCheckUsingDialog method
- Error word highlighting
- Replace and ignore operations
- Add to Dictionary functionality
📄 阅读: references/spell-check-methods.md
- 基于对话框的拼写检查
- 基于上下文菜单的建议
- PerformSpellCheckUsingDialog方法
- 错误单词高亮
- 替换和忽略操作
- 添加到词典功能
Ignore Options
忽略选项
📄 Read: references/ignore-options.md
- Ignoring email addresses
- Ignoring URLs and internet addresses
- Ignoring HTML tags
- Ignoring mixed case words
- Ignoring uppercase words
- Ignoring alphanumeric words
- Configuration examples
📄 阅读: references/ignore-options.md
- 忽略电子邮件地址
- 忽略URL和网络地址
- 忽略HTML标签
- 忽略大小写混合单词
- 忽略全大写单词
- 忽略包含数字的单词
- 配置示例
Dictionary Support
词典支持
📄 Read: references/dictionary-support.md
- Default English dictionary
- Multi-language spell checking
- Hunspell dictionary format
- Ispell dictionary format
- OpenOffice dictionary format
- Adding custom dictionaries
- Custom word lists
- Switching culture at runtime
- DictionaryCollection management
📄 阅读: references/dictionary-support.md
- 默认英语词典
- 多语言拼写检查
- Hunspell词典格式
- Ispell词典格式
- OpenOffice词典格式
- 添加自定义词典
- 自定义单词列表
- 运行时切换区域
- DictionaryCollection管理
Customization and Theming
自定义与主题
📄 Read: references/customization.md
- SpellCheckCompleted event
- Restricting completion message box
- Theme support with SfSkinManager
- ThemeStudio customization
- Visual appearance options
📄 阅读: references/customization.md
- SpellCheckCompleted事件
- 限制完成提示框
- 使用SfSkinManager支持主题
- ThemeStudio自定义
- 视觉外观选项
Quick Start
快速开始
Basic Setup with Dialog
基于对话框的基础设置
xml
<Window xmlns:syncfusion="http://schemas.syncfusion.com/wpf">
<Grid>
<StackPanel>
<TextBox
Text="Ths is a sampel text with speling errors."
Name="textbox"
TextWrapping="Wrap">
<!--Attach SpellChecker to TextBox-->
<syncfusion:SfSpellChecker.SpellChecker>
<syncfusion:SfSpellChecker
x:Name="spellChecker"
EnableSpellCheck="True"/>
</syncfusion:SfSpellChecker.SpellChecker>
</TextBox>
<Button
Content="Spell Check"
Click="SpellCheck_ButtonClick"
HorizontalAlignment="Center"/>
</StackPanel>
</Grid>
</Window>csharp
// Code-behind
private void SpellCheck_ButtonClick(object sender, RoutedEventArgs e)
{
spellChecker.PerformSpellCheckUsingDialog();
}xml
<Window xmlns:syncfusion="http://schemas.syncfusion.com/wpf">
<Grid>
<StackPanel>
<TextBox
Text="Ths is a sampel text with speling errors."
Name="textbox"
TextWrapping="Wrap">
<!--Attach SpellChecker to TextBox-->
<syncfusion:SfSpellChecker.SpellChecker>
<syncfusion:SfSpellChecker
x:Name="spellChecker"
EnableSpellCheck="True"/>
</syncfusion:SfSpellChecker.SpellChecker>
</TextBox>
<Button
Content="Spell Check"
Click="SpellCheck_ButtonClick"
HorizontalAlignment="Center"/>
</StackPanel>
</Grid>
</Window>csharp
// Code-behind
private void SpellCheck_ButtonClick(object sender, RoutedEventArgs e)
{
spellChecker.PerformSpellCheckUsingDialog();
}Quick Setup with Context Menu
基于上下文菜单的快速设置
xml
<syncfusion:SfSpellChecker
x:Name="spellChecker"
EnableSpellCheck="True"
EnableContextMenu="True"/>Users can right-click on error words (red underlined) to see suggestions.
xml
<syncfusion:SfSpellChecker
x:Name="spellChecker"
EnableSpellCheck="True"
EnableContextMenu="True"/>用户可右键点击带有红色下划线的错误单词查看建议。
Common Patterns
常见模式
Pattern 1: Basic Spell Check with Dialog
模式1:基于对话框的基础拼写检查
csharp
// Create spell checker instance
SfSpellChecker spellChecker = new SfSpellChecker();
spellChecker.EnableSpellCheck = true;
// Attach to TextBox
SfSpellChecker.SetSpellChecker(textbox, spellChecker);
// Open spell check dialog
spellChecker.PerformSpellCheckUsingDialog();csharp
// Create spell checker instance
SfSpellChecker spellChecker = new SfSpellChecker();
spellChecker.EnableSpellCheck = true;
// Attach to TextBox
SfSpellChecker.SetSpellChecker(textbox, spellChecker);
// Open spell check dialog
spellChecker.PerformSpellCheckUsingDialog();Pattern 2: Context Menu with Ignore Options
模式2:带忽略选项的上下文菜单
csharp
SfSpellChecker spellChecker = new SfSpellChecker();
spellChecker.EnableSpellCheck = true;
spellChecker.EnableContextMenu = true;
// Configure ignore options
spellChecker.IgnoreUrl = true;
spellChecker.IgnoreEmailAddress = true;
spellChecker.IgnoreUpperCaseWords = true;
SfSpellChecker.SetSpellChecker(textbox, spellChecker);csharp
SfSpellChecker spellChecker = new SfSpellChecker();
spellChecker.EnableSpellCheck = true;
spellChecker.EnableContextMenu = true;
// Configure ignore options
spellChecker.IgnoreUrl = true;
spellChecker.IgnoreEmailAddress = true;
spellChecker.IgnoreUpperCaseWords = true;
SfSpellChecker.SetSpellChecker(textbox, spellChecker);Pattern 3: Multi-Language Support
模式3:多语言支持
csharp
// Create culture-specific spell checker
CultureInfo culture = new CultureInfo("fr-FR");
SfSpellChecker spellChecker = new SfSpellChecker();
// Add French dictionary
spellChecker.Dictionaries = new DictionaryCollection();
spellChecker.Dictionaries.Add(
new HunspellDictionary()
{
Culture = culture,
GrammarUri = new Uri("/MyApp;component/Dictionaries/fr-FR.aff", UriKind.Relative),
DictionaryUri = new Uri("/MyApp;component/Dictionaries/fr-FR.dic", UriKind.Relative)
}
);
spellChecker.Culture = culture;
SfSpellChecker.SetSpellChecker(textbox, spellChecker);csharp
// Create culture-specific spell checker
CultureInfo culture = new CultureInfo("fr-FR");
SfSpellChecker spellChecker = new SfSpellChecker();
// Add French dictionary
spellChecker.Dictionaries = new DictionaryCollection();
spellChecker.Dictionaries.Add(
new HunspellDictionary()
{
Culture = culture,
GrammarUri = new Uri("/MyApp;component/Dictionaries/fr-FR.aff", UriKind.Relative),
DictionaryUri = new Uri("/MyApp;component/Dictionaries/fr-FR.dic", UriKind.Relative)
}
);
spellChecker.Culture = culture;
SfSpellChecker.SetSpellChecker(textbox, spellChecker);Pattern 4: Custom Dictionary
模式4:自定义词典
csharp
// Add custom words dictionary
Uri customDictUri = new Uri(Directory.GetCurrentDirectory() +
@"\Dictionaries\CustomWords.txt", UriKind.Absolute);
spellChecker.Dictionaries.Add(
new CustomDictionary()
{
Culture = new CultureInfo("en-US"),
DictionaryUri = customDictUri
}
);csharp
// Add custom words dictionary
Uri customDictUri = new Uri(Directory.GetCurrentDirectory() +
@"\Dictionaries\CustomWords.txt", UriKind.Absolute);
spellChecker.Dictionaries.Add(
new CustomDictionary()
{
Culture = new CultureInfo("en-US"),
DictionaryUri = customDictUri
}
);Pattern 5: Handle Spell Check Completion
模式5:处理拼写检查完成事件
csharp
spellChecker.SpellCheckCompleted += (sender, e) =>
{
// Suppress default message box
(e as SpellCheckCompletedEventArgs).ShowMessageBox = false;
// Custom completion logic
MessageBox.Show("Spell check completed!", "Done");
};csharp
spellChecker.SpellCheckCompleted += (sender, e) =>
{
// Suppress default message box
(e as SpellCheckCompletedEventArgs).ShowMessageBox = false;
// Custom completion logic
MessageBox.Show("Spell check completed!", "Done");
};Key Properties
核心属性
| Property | Type | Description |
|---|---|---|
| bool | Enable/disable spell checking (default: true) |
| bool | Enable context menu suggestions (default: true) |
| CultureInfo | Culture for spell checking |
| DictionaryCollection | Collection of dictionaries |
| bool | Ignore internet addresses |
| bool | Ignore email addresses |
| bool | Ignore HTML tags |
| bool | Ignore mixed case words (e.g., AbCDeFH) |
| bool | Ignore all uppercase words |
| bool | Ignore words with numbers |
| 属性 | 类型 | 说明 |
|---|---|---|
| bool | 启用/禁用拼写检查(默认值:true) |
| bool | 启用上下文菜单建议(默认值:true) |
| CultureInfo | 拼写检查使用的区域设置 |
| DictionaryCollection | 词典集合 |
| bool | 忽略网络地址 |
| bool | 忽略电子邮件地址 |
| bool | 忽略HTML标签 |
| bool | 忽略大小写混合的单词(例如:AbCDeFH) |
| bool | 忽略所有大写的单词 |
| bool | 忽略包含数字的单词 |
Key Methods
核心方法
| Method | Description |
|---|---|
| Opens spell check dialog |
| Gets suggestion list for error word |
| Gets phonetic word suggestions |
| Gets anagram suggestions |
| 方法 | 说明 |
|---|---|
| 打开拼写检查对话框 |
| 获取错误单词的建议列表 |
| 获取语音相似的单词建议 |
| 获取变位词建议 |
Common Use Cases
常见使用场景
- Text Editor with Spell Check - Add comprehensive spell checking to WPF text editors
- Multi-Language Document Editor - Support multiple languages with culture-specific dictionaries
- Custom Domain Dictionary - Add industry-specific or company-specific terms
- Email Client - Spell check with email/URL ignore options
- HTML Editor - Spell check while ignoring HTML markup
- Form Validation - Validate text input fields for spelling errors
- Accessible Text Input - Provide context menu for easy error correction
- 带拼写检查的文本编辑器 - 为WPF文本编辑器添加全面的拼写检查功能
- 多语言文档编辑器 - 支持多语言的区域特定词典
- 自定义领域词典 - 添加行业特定或公司特定术语
- 电子邮件客户端 - 带电子邮件/URL忽略选项的拼写检查
- HTML编辑器 - 忽略HTML标记的拼写检查
- 表单验证 - 验证文本输入字段的拼写错误
- 可访问文本输入 - 提供上下文菜单以便轻松纠正错误
Sample Applications
示例应用
GitHub samples: WPF SpellChecker Examples
GitHub示例:WPF SpellChecker Examples