Skip to main content
A newer version of this page is available. .

Lesson 1 - Configure Spell Checking Behavior

  • 3 minutes to read

In MVVM-based applications, you can add the spell-checking functionality to the RichEditControl or any other supported text editor using the SpellChecker behavior mechanism.

This topic shows how to add the SpellChecker behavior to the RichEditControl and other supported text editors.

Add RichEditSpellChecker Behavior to the RichEditControl

Perform the following steps to add the spell-checking functionality to the RichEditControl:

  1. Open the RichEditControl’ smart tag and click MVVM Behaviors and Services button;

    DXSpellChecker_RichEditControlBehavior_Step1

  2. Click the Add behavior item and select RichEditSpellChecker from the invoked list;

    DXSpellChecker_RichEditControlBehavior_Step2

  3. Specify the desired properties in the invoked RichEditSpellChecker menu.

    DXSpellChecker_RichEditControlBehavior_Step3

  4. You can add dictionaries to the SpellCheckerDictionaryCollection directly in XAML. The SpellChecker supports using Simple, ISpell, OpenOffice and a Hunspell dictionaries. Refer to the Dictionaries topic for details.

    The RichEditSpellChecker uses the dictionary that corresponds with the RichEditSpellChecker.Culture value. Make sure that dictionaries for all used cultures are added to the DictionaryCollection.

    As a result, the XAML code looks as shown in the code snippet below.

    <dxre:RichEditControl DocumentSource="An ideal dictionarie shouldbe comprised of all the the words in a given langauge">
        <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>
    

    You can add this code directly to the MainWindow.xaml document. Before that, make sure that the following namespace attributes are added:

    xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
    xmlns:dxspch="http://schemas.devexpress.com/winfx/2008/xaml/spellchecker"
    

Add DXSpellChecker Behavior to Other Text Editors

The DXSpellChecker behavior smart tag configuration is available for DevExpress TextEdit and MemoEdit, and standard TextBox and RichTextBox controls. Follow the steps below to implement the spell checking functionality to any of these controls:

  1. Open the editor’s smart tag and click MVVM Behaviors and Services button;

    DXSpellChecker_TextEditor_Behavior_Step1

  2. Click the Add behavior item and select DXSpellChecker from the invoked list;

    DXSpellChecker_TextEditors_Behaviors_Step2

  3. Specify the desired properties in the invoked DXSpellChecker menu.

    DXSpellChecker_TextEditors_Step3

  4. You can add dictionaries to the SpellCheckerDictionaryCollection directly in XAML. The SpellChecker supports using Simple, ISpell, OpenOffice and a Hunspell dictionaries. Refer to the Dictionaries topic for details.

    The DXSpellChecker uses the dictionary that corresponds with the DXSpellChecker.Culture value. Make sure that dictionaries for all used cultures are added to the DictionaryCollection.

    Tip

    Refer to the How to: Bind Dictionaries to the Spell Checker in MVVM Applications topic for an example on how to bind dictionaries in MVVM-based applications.

    As a result, the XAML code looks as follows:

    <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>
    

    You can add this code directly to the MainWindow.xaml document. Before that, make sure that the following namespace attributes are added:

    xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
    xmlns:dxspch="http://schemas.devexpress.com/winfx/2008/xaml/spellchecker"