Skip to main content

Configure Spell-Checking Behavior

  • 4 minutes to read

In MVVM-based applications, you can add spell-checking behavior to the Rich Text Editor or other text-aware controls to check spelling.

Install the WPF Spell Checker Component

You can use the DevExpress NuGet feed to install the DevExpress.Wpf.SpellChecker NuGet package. Refer to the following section for instructions: Choose Between Offline and Online DevExpress NuGet Feeds.

After you access DevExpress NuGet packages and register the DevExpress NuGet feed, install the DevExpress.Wpf.SpellChecker NuGet package as follows:

  1. Go to Tools | NuGet Package Manager | Manage NuGet Packages for Solution.
  2. Select the DevExpress NuGet feed as a package source.
  3. Install the DevExpress.Wpf.SpellChecker NuGet package to use the Spell Checker within your WPF application.

Add the SpellChecker NuGet Package

Add Spell-Checking Behavior to the Rich Text Editor

To integrate the Spell Checker into the WPF Rich Text Editor, implement the RichEditSpellChecker behavior as described below.

Add RichEditSpellChecker Behavior

Create a WPF Rich Text Editor application that contains the RichEditControl. For more information, see Create a Simple Rich Text Editor.

Open the MainWindow.xaml file in the Visual Studio designer. Select the RichEditControl and invoke its Quick Actions.

In the invoked menu, go to the Behaviors tab and select the Add the DevExpress.Wpf.SpellChecker package… task to install the DevExpress.Wpf.SpellChecker NuGet package (if you create a .NET Framework application, click this command to add a reference to the DevExpress.Xpf.SpellChecker.v24.1.dll library).

Add the SpellChecker package

Select RichEditSpellChecker from the drop-down list, and click Add to add the spell-checking behavior to the RichEditControl.

Select the Spell Checker

Specify the RichEditSpellChecker object’s properties in the invoked menu.

Specify the Spell Checker's properties

Add Spelling Dictionaries

The RichEditSpellChecker component supports Simple, ISpell, OpenOffice, and Hunspell dictionaries. You can add dictionaries to the RichEditSpellChecker in XAML. Use the RichEditSpellChecker.Dictionaries property to access the SpellCheckerDictionaryCollection and add items as follows:

View Example

View Example

<Window
    x:Class="RichEditSpellChecker_Example.MainWindow"
    xmlns:dxre="http://schemas.devexpress.com/winfx/2008/xaml/richedit"
    xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
    xmlns:dxspch="http://schemas.devexpress.com/winfx/2008/xaml/spellchecker"
    Height="350"
    Width="525"
    mc:Ignorable="d"
    Title="MainWindow">
    <Grid>
        <dxre:RichEditControl DocumentSource="An ideal dictionarie shouldbe comprised of all the the words in a given langauge">
         <dxre:RichEditControl.SpellCheckerOptions>
                <dxre:DXRichEditSpellCheckerOptions AutoDetectDocumentCulture="True"/>
        </dxre:RichEditControl.SpellCheckerOptions>
            <dxmvvm:Interaction.Behaviors>
                <dxspch:RichEditSpellChecker CheckAsYouType="True"
                                             Culture="en-US"
                                             IgnoreMixedCaseWords="False"
                                             IgnoreUri="False"
                                             SpellingFormType="Word">
                    <dxspch:RichEditSpellChecker.Dictionaries>
                        <dxspch:HunspellDictionary Culture="en-US" 
                                                   DictionaryUri="pack://application:,,,/Dictionaries/en_US.dic"
                                                   GrammarUri="pack://application:,,,/Dictionaries/en_US.aff"/>
                        <dxspch:SpellCheckerCustomDictionary Culture="en-US"
                                                             DictionaryUri="Dictionaries/CustomEnglish.dic"
                                                             AlphabetUri="Dictionaries/EnglishAlphabet.txt"/>
                    </dxspch:RichEditSpellChecker.Dictionaries>
                </dxspch:RichEditSpellChecker>
            </dxmvvm:Interaction.Behaviors>
        </dxre:RichEditControl>
    </Grid>
</Window>

Run the application to view the result.

Check the Text Spelling

Important Notes

Consider the following when you implement the RichEditSpellChecker behavior:

Add Spell-Checking Behavior to Other Text Editors

You can integrate the Spell Checker into the DevExpress TextEdit and MemoEdit, and standard TextBox and RichTextBox controls. To do this, implement the DXSpellChecker behavior as described below.

Create a new WPF Application and open the MainWindow.xaml file in the Visual Studio designer. Add a supported text editor to your project.

If you add a standard text editor (TextBox or RichTextBox), use the DevExpress NuGet feed to install the DevExpress.Wpf.SpellChecker NuGet package. After you install the SpellChecker package, the Behavior tab appears in the editor’s Quick Actions. If you create a .NET Framework application, add a reference to the DevExpress.Xpf.SpellChecker.v24.1.dll library.

Select the Spell Checker

If you add a DevExpress text editor (TextEdit or MemoEdit), invoke the editor’s Quick Actions, go to the Behaviors tab, and select the Add the DevExpress.Wpf.SpellChecker package… task to install the DevExpress.Wpf.SpellChecker NuGet package. If you create a .NET Framework application, click this command to add a reference to the DevExpress.Xpf.SpellChecker.v24.1.dll library.

Add the SpellChecker package

After you install the DevExpress.Wpf.SpellChecker NuGet package, select DXSpellChecker from the drop-down list. Click Add to attach spell checking behavior to the text editor. Specify the DXSpellChecker object’s properties in the invoked menu.

Specify the Spell Checker's properties

The DXSpellChecker supports the Simple, ISpell, OpenOffice, and Hunspell dictionaries. You can add dictionaries to the DXSpellChecker in XAML. Use the DXSpellChecker.Dictionaries property to access the dictionary collection (SpellCheckerDictionaryCollection) and add items as follows:

<!--Add the following namespace declarations: 
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
xmlns:dxspch="http://schemas.devexpress.com/winfx/2008/xaml/spellchecker"-->

<dxe:TextEdit Text="An ideal dictionarie shouldbe comprised of all the the words in a given langauge">
    <dxmvvm:Interaction.Behaviors>
        <dxspch:DXSpellChecker x:Name="spChecker"
                               UnderlineColor="#FFAA3A37" 
                               IgnoreEmails="False" 
                               Culture="en-US" 
                               ShowSpellCheckMenu="True"
                               CheckAsYouType="True" 
                               SpellingFormType="Word">         
            <dxspch:DXSpellChecker.Dictionaries>
                <dxspch:SpellCheckerISpellDictionary AlphabetUri="Dictionaries/EnglishAlphabet.txt" 
                                                     Culture="en-US" 
                                                     DictionaryUri="pack://siteoforigin:,,,/Dictionaries/american.xlg" 
                                                     GrammarUri="pack://siteoforigin:,,,/Dictionaries/english.aff"/>
            </dxspch:DXSpellChecker.Dictionaries>
        </dxspch:DXSpellChecker>
    </dxmvvm:Interaction.Behaviors>            
</dxe:TextEdit>

Run the application to view the result.

Check the Text Spelling

Important Notes

  • The DXSpellChecker uses the dictionary that corresponds with the DXSpellChecker.Culture property value. Make sure that you populate the SpellCheckerDictionaryCollection with corresponding dictionaries for all used cultures. Refer to the following topics for more information about dictionaries and their binding:

  • Text editors that support DXSpellChecker do not have API to obtain spell checker in code-behind. If your scenario requires to track checking process or manage user interaction, you can use the standalone SpellChecker object or the MVVM approach.