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.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-bind-dictionaries-to-the-spell-checker-in-mvvm-applications-t604129.
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");
collection.Add(dictionary);
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:
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-bind-dictionaries-to-the-spell-checker-in-mvvm-applications-t604129.
<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."
TextWrapping="Wrap"
dxsch:SpellingSettings.DictionarySourceCollection="{Binding Dictionaries,UpdateSourceTrigger=PropertyChanged}">
<dxmvvm:Interaction.Behaviors>
<dxsch:DXSpellChecker Culture="de-DE"
CheckAsYouType="True"
SpellingFormType="Word"
ShowSpellCheckMenu="True"/>
</dxmvvm:Interaction.Behaviors>
</dxe:TextEdit>