Spell Check in WPF DOCX Editor

18 Aug 20263 minutes to read

The WPF RichTextBox (SfRichTextBoxAdv) provides support for checking spelling mistakes in the rich text document content through the SpellChecker property of type SpellChecker. It also supports enabling the following spell checking options.

  • Ignore words in UPPERCASE.

  • Ignore words that contain numbers.

  • Ignore URIs.

The following sample code demonstrates how to enable spell checker in SfRichTextBoxAdv.

<RichTextBoxAdv:SfRichTextBoxAdv x:Name="richTextBoxAdv"  xmlns:RichTextBoxAdv="clr-namespace:Syncfusion.Windows.Controls.RichTextBoxAdv;assembly=Syncfusion.SfRichTextBoxAdv.Wpf">
    <RichTextBoxAdv:SfRichTextBoxAdv.SpellChecker>
        <RichTextBoxAdv:SpellChecker IsEnabled="True" IgnoreURIs="true" IgnoreAlphaNumericWords="true" IgnoreUppercaseWords="true"/>
    </RichTextBoxAdv:SfRichTextBoxAdv.SpellChecker>
</RichTextBoxAdv:SfRichTextBoxAdv>
// Enables spell checker in RichTextBoxAdv.
richTextBoxAdv.SpellChecker.IsEnabled = true;

// Ignores alpha numeric words while spell check.
richTextBoxAdv.SpellChecker.IgnoreAlphaNumericWords = true;

// Ignores upper case words while spell check.
richTextBoxAdv.SpellChecker.IgnoreUppercaseWords = true;

// Ignores URIs while spell check.
richTextBoxAdv.SpellChecker.IgnoreURIs = true;
' Enables spell checker in RichTextBoxAdv.
richTextBoxAdv.SpellChecker.IsEnabled = True

' Ignores alpha numeric words while spell check.
richTextBoxAdv.SpellChecker.IgnoreAlphaNumericWords = True

' Ignores upper case words while spell check.
richTextBoxAdv.SpellChecker.IgnoreUppercaseWords = True

' Ignores URIs while spell check.
richTextBoxAdv.SpellChecker.IgnoreURIs = True

Adding custom dictionaries

The SfRichTextBoxAdv also supports defining custom dictionaries that can be referred to while checking spelling mistakes. The SfRichTextBoxAdv ignores words that are defined in the referenced custom dictionaries. The SfRichTextBoxAdv supports the option of adding a misspelled word to a dictionary. This option will be enabled only when at least one custom dictionary is defined. The misspelled words are added to the first item in the CustomDictionaries collection.
The following code example demonstrates how to define custom dictionaries for spell checking.

<!-- xmlns:System="clr-namespace:System;assembly=mscorlib" -->
<!-- xmlns:RichTextBoxAdv="clr-namespace:Syncfusion.Windows.Controls.RichTextBoxAdv;assembly=Syncfusion.SfRichTextBoxAdv.Wpf" -->

<RichTextBoxAdv:SpellChecker IsEnabled="True" IgnoreURIs="true" IgnoreAlphaNumericWords="true" IgnoreUppercaseWords="true">
    <RichTextBoxAdv:SpellChecker.CustomDictionaries>
        <System:String>../../Assets/DefaultDictionary.dic</System:String>
        <System:String>../../Assets/CustomDictionary.dic</System:String>
    </RichTextBoxAdv:SpellChecker.CustomDictionaries>
</RichTextBoxAdv:SpellChecker>

You can download a complete working sample from GitHub.

Multilingual spell check support

The SfRichTextBoxAdv provides support for checking spelling mistakes based on multiple languages. You can do so by defining the Language property of the SfRichTextBoxAdv control.

NOTE

In order to enable spell checking functionality based on a particular language, the language pack for .NET Framework must be installed on the machine.

The following code example demonstrates how to enable spell checking based on language.

<RichTextBoxAdv:SfRichTextBoxAdv x:Name="richTextBoxAdv"  xmlns:RichTextBoxAdv="clr-namespace:Syncfusion.Windows.Controls.RichTextBoxAdv;assembly=Syncfusion.SfRichTextBoxAdv.Wpf" Language="fr">
    <RichTextBoxAdv:SfRichTextBoxAdv.SpellChecker>
        <RichTextBoxAdv:SpellChecker IsEnabled="True" IgnoreURIs="true" IgnoreAlphaNumericWords="true" IgnoreUppercaseWords="true"/>
    </RichTextBoxAdv:SfRichTextBoxAdv.SpellChecker>
</RichTextBoxAdv:SfRichTextBoxAdv>

Spelling pane

The SfRichTextBoxAdv provides built-in spelling pane support for checking spelling mistakes and correcting error words, similar to the Microsoft Word application.

The following code example demonstrates how to show the spelling pane in SfRichTextBoxAdv through the ShowSpellingPaneCommand command binding.

<!-- Binding Button to UI Command that shows the spelling pane  -->
<Button Content="Show Spelling Pane" Command="RichTextBoxAdv:SfRichTextBoxAdv.ShowSpellingPaneCommand" CommandTarget="{Binding ElementName=richTextBoxAdv}" />

WPF RichTextBox displays spellcheck option

NOTE

You can refer to our WPF RichTextBox feature tour page for its groundbreaking feature representations. You can also explore our WPF RichTextBox example to know how to render and configure the editing tool.

See also