How to: Bind Dictionaries to the Spell Checker in MVVM Applications

  • 2 minutes to read

The following code sample shows how to use the SpellingSettings.DictionarySourceCollection attached property to bind dictionaries generated at runtime to the Spellchecker in MVVM-based applications.

In this example, the TextEdit is used to display text. The dictionary collection is generated in the ViewModel.

View Example

public class MainViewModel
    public virtual DictionarySourceCollection Dictionaries { get; set; }
    public MainViewModel()
        Dictionaries = GetDictionaries();

    public DictionarySourceCollection GetDictionaries()
        var collection = new DictionarySourceCollection();

        var dictionary = new HunspellDictionarySource();
        dictionary.Culture = new CultureInfo("de-DE");            
        dictionary.DictionaryUri = new Uri(@"pack://application:,,,/Dictionaries/de_DE.dic");
        dictionary.GrammarUri = new Uri(@"pack://application:,,,/Dictionaries/de_DE.aff");
        return collection;

Implement the DXSpellChecker behavior and bind the dictionaries to the SpellingSettings.DictionarySourceCollection property to provide the TextEdit with the spell checking functionality, as shown below:

View Example

<dxe:TextEdit x:Name="textEdit1"
              Text=" Jeder hat das Regcht, am kulturelen Leben der Gemeinschaft frei teilzunehmen, sich an den Künsten zu erfreuen und am wissenschaftlichen Fortschritt und dessen Errungenschaften teilzuhaben."
              dxsch:SpellingSettings.DictionarySourceCollection="{Binding Dictionaries,UpdateSourceTrigger=PropertyChanged}">
        <dxsch:DXSpellChecker Culture="de-DE" 
See Also