Skip to main content

Dictionaries

  • 3 minutes to read

Supported Dictionaries

The Spell Checker for WPF supports the following dictionaries:

If no dictionary is specified and the SpellCheckerBase<T>.Culture property is set to EN-US, the SpellChecker uses the default English dictionary. When other dictionaries are added, the default dictionary is not loaded.

The table below compares supported dictionaries:

Simple ISpell OpenOffice Hunspell Custom
Popularity Low Low High High High
Word Detection Speed Fast Fast Fast Slow Fast
Size Large Large Large Small Various
Dictionary File Format .dic, .txt .xlg, .dic .dic .dic .dic, .txt
Grammar File (.aff) Required No Yes Yes Yes No
API Reference (XAML) SpellCheckerISpellDictionaryExtension SpellCheckerOpenOfficeDictionaryExtension HunspellDictionaryExtension SpellCheckerCustomDictionaryExtension
API Reference (Code-Behind) SpellCheckerDictionary SpellCheckerISpellDictionary SpellCheckerOpenOfficeDictionary HunspellDictionary SpellCheckerCustomDictionary

Warning

Note that the OpenOffice license cannot be used for commercial projects. Please ensure the relevant license agreement permits use within your application or project.

Custom Dictionary

Add a custom dictionary to store users’ word additions. Users can add an entry from the Spelling Dialog and use the Spelling Options Dialog to edit the dictionary.

The SpellChecker overrides a custom dictionary every time users add new words or edit the word list - this file should not be set to read-only. If the dictionary is not available, ensure another process does not use it.

Add Dictionaries in XAML

You can add dictionaries to the DXSpellChecker and RichEditSpellChecker in XAML. Access the SpellCheckerBase<T>.Dictionaries property and add items as shows below:

<dxmvvm:Interaction.Behaviors>
    <dxspch:RichEditSpellChecker Culture="en-US">
        <dxspch:RichEditSpellChecker.Dictionaries>
            <dxspch:HunspellDictionary Culture="de-DE"
                                        DictionaryUri="pack://application:,,,/Dictionaries/de-DE.dic"
                                        GrammarUri="pack://application:,,,/Dictionaries/de-DE.aff"/>
            <dxspch:SpellCheckerCustomDictionary Culture="en-US"
                                                    DictionaryUri="Dictionaries/CustomEnglish.dic"
                                                    AlphabetUri="Dictionaries/EnglishAlphabet.txt"/>
            <dxspch:SpellCheckerOpenOfficeDictionary Culture="ru-RU"
                                                        DictionaryUri="pack://application:,,,/Dictionaries/ru_RU.dic"
                                                        GrammarUri="pack://application:,,,/Dictionaries/ru_RU.aff"/>
            <dxspch:SpellCheckerISpellDictionary Culture="en-US"
                                                    DictionaryUri="pack://application:,,,/Dictionaries/american.xlg"
                                                    GrammarUri="pack://application:,,,/Dictionaries/english.dic"/>
        </dxspch:RichEditSpellChecker.Dictionaries>
    </dxspch:RichEditSpellChecker>
</dxmvvm:Interaction.Behaviors>

Add Dictionaries in Code-Behind

If you use the SpellChecker object, add dictionaries to the DevExpress.XtraSpellChecker.DictionaryCollection. Use the SpellCheckerBase.Dictionaries property to access the dictionary collection.

DictionaryCollection spellCheckerDictionaries = spellChecker.Dictionaries;
SpellCheckerOpenOfficeDictionary russianDictionary = new SpellCheckerOpenOfficeDictionary("/Dictionaries//OpenOffice//ru_RU.dic", "/Dictionaries//OpenOffice//ru_RU.aff", new CultureInfo("ru_RU"));
spellCheckerDictionaries.Add(russianDictionary);

SpellCheckerISpellDictionary englishDictionary = new SpellCheckerISpellDictionary("/Dictionaries//ISpell//american.xlg", "/Dictionaries//ISpell//english.aff", new CultureInfo("en_US"));
spellCheckerDictionaries.Add(englishDictionary);

HunspellDictionary germanDictionary = new HunspellDictionary("/Dictionaries//HunSpell//de_DE.dic", "/Dictionaries//HunSpell//de_DE.aff", new CultureInfo("de_DE"));
spellCheckerDictionaries.Add(germanDictionary);

SpellCheckerCustomDictionary customDictionary = new SpellCheckerCustomDictionary("/Dictionaries//Custom//CustomEnglish.dic", new CultureInfo("en_US"));
spellCheckerDictionaries.Add(customDictionary);

After each dictionary is successfully loaded, the DictionaryBase.DictionaryLoaded event fires. You can subscribe to the SpellCheckerBase.UnhandledException event to catch an unhandled exception which may happen while dictionary is loaded and prepared for use.

Tip

Refer to the How to: Bind Dictionaries to the Spell Checker in MVVM Applications topic for information on how to bind dictionaries generated at runtime to the Spellchecker in MVVM-based applications.