Custom Dictionary in WPF SpellChecker (SfSpellChecker)
18 Feb 202524 minutes to read
You can use a default and custom dictionaries to spell check the document based on your need. You can also spell check for any culture and languages using various dictionaries.
Default SpellCheck Dictionary
SfSpellChecker provides built-in dictionary for English language and it provides suitable suggestion of the error words.
Load your own dictionaries for any language
You can add your own dictionary to SfSpellChecker.Dictionaries collection. SfSpellChecker support 3 standard dictionary file format:
- 1.Hunspell
- 2.Ispell
- 3.OpenOffice
NOTE
Built-in dictionary will be disabled once custom dictionary is added to SfSpellChecker
SpellCheck using Hunspell dictionary
You can check spelling mistakes using Hunspell dictionary format. This format contains files as follows,
- Affix file with grammar rules-
*.aff, - Basic Words file -
*.dicfile.
Adding Hunspell Dictionary
- Add your HunspellDictionary’s required culture
*.affand*.dicfiles and add them asResourceinto the application.

-
Create a
HunspellDictionaryinstance and add the basic word & grammar file path to the HunspellDictionary.DictionaryUri & HunspellDictionary.GrammarUri properties and add the culture to the HunspellDictionary.Culture property. -
Add the
HunspellDictionaryinto theSfSpellChecker.Dictionariescollection -
Setting the required culture to the SfSpellChecker.Culture property.
NOTE
The following code snippets shows how to add Hunspell dictionary to the
SpellChecker. Please refer Adding SfSpellChecker to an application to know how to configure SfSpellChecker.
<Grid>
<StackPanel>
<TextBox
Text="Nous sommevs heureusre de vous avochir ici"
Name="textbox"
TextWrapping="Wrap">
<!--Adding Spellchecker to the TextBox-->
<syncfusion:SfSpellChecker.SpellChecker>
<syncfusion:SfSpellChecker
Culture="fr-FR"
x:Name="spellChecker"
EnableSpellCheck="True">
<syncfusion:SfSpellChecker.Dictionaries>
<!--Adding French cultured Hunspell dictionary-->
<syncfusion:HunspellDictionary DictionaryUri="/HunSpellCheck;component/French/fr-FR.dic"
GrammarUri="/HunSpellCheck;component/French/fr-FR.aff"
Culture="fr-FR"/>
</syncfusion:SfSpellChecker.Dictionaries>
</syncfusion:SfSpellChecker>
</syncfusion:SfSpellChecker.SpellChecker>
</TextBox>
<Button
Content="Spell Check"
Click="SpellCheck_ButtonClick"
HorizontalAlignment="Center"></Button>
</StackPanel>
</Grid>//Creating a culture instance
CultureInfo culture = new CultureInfo("fr-FR");
SfSpellChecker spellChecker = new SfSpellChecker();
// Adding Hunspell dictonaries in Dictionaries collection
spellChecker.Dictionaries = new DictionaryCollection();
//Add French culture Hunspell dictionary
spellChecker.Dictionaries.Add(
new HunspellDictionary()
{
Culture = culture,
GrammarUri = new Uri("/HunSpellCheck;component/French/fr-FR.aff", UriKind.Relative),
DictionaryUri = new Uri("/HunSpellCheck;component/French/fr-FR.dic", UriKind.Relative)
}
);
//Setting a French culture for SpellChecker
spellChecker.Culture = culture;
//Assigning a spellchecker to the TextBox
SfSpellChecker.SetSpellChecker(textbox, spellChecker);//Call SpellCheck method to open SpellCheck on button click
private void SpellCheck_ButtonClick(object sender, RoutedEventArgs e) {
spellChecker.PerformSpellCheckUsingDialog();
}NOTE
You can add multiple
HunspellDictionarywith various culture files into theSfSpellChecker.Dictionariescollection. Based on theSfSpellChecker.CulturerespectiveHunspellDictionaryis used for spell check.

SpellCheck using Ispell dictionary
You can check spelling mistakes using Ispell dictionary format. This format contains files as follows,
Ispell dictionary contains two files as follows,
- Affix file with grammar rules-
*.aff, - Basic Words file -
*.xlgor*.dicfile.
Adding Ispell Dictionary
- Add your IspellDictionary’s required culture
*.affand*.dicfiles and add them asResourceinto the application.

-
Create a
IspellDictionaryinstance and add the basic word & grammar file path to the IspellDictionary.DictionaryUri & IspellDictionary.GrammarUri properties and add the culture to the IspellDictionary.Culture property. -
Add the
IspellDictionaryinto theSfSpellChecker.Dictionariescollection -
Setting the required culture to the
SfSpellChecker.Cultureproperty.<Grid> <StackPanel> <TextBox Text="gracsq por venizr por favor ven de nuevoq" Name="textbox" TextWrapping="Wrap"> <!--Adding Spellchecker to the TextBox--> <syncfusion:SfSpellChecker.SpellChecker> <syncfusion:SfSpellChecker Culture="es-ES" x:Name="spellChecker" EnableSpellCheck="True"> <syncfusion:SfSpellChecker.Dictionaries> <!--Adding Spanish cultured Ispell dictionary--> <syncfusion:IspellDictionary DictionaryUri="/IspellCheck;component/Spanish/es-ES.dic" GrammarUri="/IspellCheck;component/Spanish/es-ES.aff" Culture="es-ES"/> </syncfusion:SfSpellChecker.Dictionaries> </syncfusion:SfSpellChecker> </syncfusion:SfSpellChecker.SpellChecker> </TextBox> <Button Content="Spell Check" Click="SpellCheck_ButtonClick" HorizontalAlignment="Center"></Button> </StackPanel> </Grid>//Creating a culture instance CultureInfo culture = new CultureInfo("es-ES"); SfSpellChecker spellChecker = new SfSpellChecker(); // Adding Ispell dictonaries in Dictionaries collection spellChecker.Dictionaries = new DictionaryCollection(); //Add Spanish culture Ispell dictionary spellChecker.Dictionaries.Add( new IspellDictionary() { Culture = culture, GrammarUri = new Uri("/IspellCheck;component/Spanish/es-ES.aff", UriKind.Relative), DictionaryUri = new Uri("/IspellCheck;component/Spanish/es-ES.dic", UriKind.Relative) } ); //Setting a Spanish culture for SpellChecker spellChecker.Culture = culture; //Assigning a spellchecker to the TextBox SfSpellChecker.SetSpellChecker(textbox, spellChecker);<div class="tabs"> <ul class="nav nav-tabs" role="tablist"> <li role="presentation" class=""><a data-target="#4h7isq0c85zznes9s2bhht0gm0k2u3h6-csharp" aria-controls="home" role="tab" data-toggle="tab" data-original-lang="csharp">C#</a></li> </ul> <div class="tab-content"> <div role="tabpanel" class="tab-pane" id="4h7isq0c85zznes9s2bhht0gm0k2u3h6-csharp" data-original-lang = "csharp" ><div class="highlight"><pre><code class="language-csharp" data-lang="csharp"><span></span><span class="c1">//Call SpellCheck method to open SpellCheck on button click</span> <span class="k">private</span> <span class="k">void</span> <span class="nf">SpellCheck_ButtonClick</span><span class="p">(</span><span class="kt">object</span> <span class="n">sender</span><span class="p">,</span> <span class="n">RoutedEventArgs</span> <span class="n">e</span><span class="p">)</span> <span class="p">{</span> <span class="n">spellChecker</span><span class="p">.</span><span class="n">PerformSpellCheckUsingDialog</span><span class="p">();</span> <span class="p">}</span></code></pre></div> </div> </div> </div>
NOTE
You can add multiple
IspellDictionarywith various culture files into theSfSpellChecker.Dictionariescollection. Based on theSfSpellChecker.CulturerespectiveIspellDictionaryis used for spell check.

SpellCheck using OpenOffice dictionary
You can check spelling mistakes using OpenOffice dictionary format. This format contains files as follows,
OpenOffice dictionary contains two files as follows,
- Affix file with grammar rules-
*.aff, - Basic Words file -
*.dicfile.
Adding OpenOffice Dictionary
- Add your OpenOfficeDictionary’s required culture
*.affand*.dicfiles and add them asResourceinto the application.

-
Create a
OpenOfficeDictionaryinstance and add the basic word & grammar file path to the OpenOfficeDictionary.DictionaryUri & OpenOfficeDictionary.GrammarUri properties and add the culture to the OpenOfficeDictionary.Culture property. -
Add the
OpenOfficeDictionaryinto theSfSpellChecker.Dictionariescollection -
Setting the required culture to the
SfSpellChecker.Cultureproperty.<Grid> <StackPanel> <TextBox Text="gracsq por venizr por favor ven de nuevoq" Name="textbox" TextWrapping="Wrap"> <!--Adding Spellchecker to the TextBox--> <syncfusion:SfSpellChecker.SpellChecker> <syncfusion:SfSpellChecker Culture="es-ES" x:Name="spellChecker" EnableSpellCheck="True"> <syncfusion:SfSpellChecker.Dictionaries> <!--Adding Spanish cultured OpenOffice dictionary--> <syncfusion:OpenOfficeDictionary DictionaryUri="/OpenOfficeSpellCheck;component/Spanish/es-ES.dic" GrammarUri="/OpenOfficeSpellCheck;component/Spanish/es-ES.aff" Culture="es-ES"/> </syncfusion:SfSpellChecker.Dictionaries> </syncfusion:SfSpellChecker> </syncfusion:SfSpellChecker.SpellChecker> </TextBox> <Button Content="Spell Check" Click="SpellCheck_ButtonClick" HorizontalAlignment="Center"></Button> </StackPanel> </Grid>//Creating a Spanish culture instance CultureInfo culture = new CultureInfo("es-ES"); SfSpellChecker spellChecker = new SfSpellChecker(); // Adding OpenOffice dictonaries in Dictionaries collection spellChecker.Dictionaries = new DictionaryCollection(); //Add Spanish culture OpenOffice dictionary spellChecker.Dictionaries.Add( new OpenOfficeDictionary() { Culture = culture, GrammarUri = new Uri("/OpenOfficeSpellCheck;component/Spanish/es-ES.aff", UriKind.Relative), DictionaryUri = new Uri("/OpenOfficeSpellCheck;component/Spanish/es-ES.dic", UriKind.Relative) } ); //Setting a Spanish culture for SpellChecker spellChecker.Culture = culture; //Assigning a spellchecker to the TextBox SfSpellChecker.SetSpellChecker(textbox, spellChecker);<div class="tabs"> <ul class="nav nav-tabs" role="tablist"> <li role="presentation" class=""><a data-target="#k3ido4kx67lz3grcdx3fegnpvwfzoag2-csharp" aria-controls="home" role="tab" data-toggle="tab" data-original-lang="csharp">C#</a></li> </ul> <div class="tab-content"> <div role="tabpanel" class="tab-pane" id="k3ido4kx67lz3grcdx3fegnpvwfzoag2-csharp" data-original-lang = "csharp" ><div class="highlight"><pre><code class="language-csharp" data-lang="csharp"><span></span><span class="c1">//Call SpellCheck method to open SpellCheck on button click</span> <span class="k">private</span> <span class="k">void</span> <span class="nf">SpellCheck_ButtonClick</span><span class="p">(</span><span class="kt">object</span> <span class="n">sender</span><span class="p">,</span> <span class="n">RoutedEventArgs</span> <span class="n">e</span><span class="p">)</span> <span class="p">{</span> <span class="n">spellChecker</span><span class="p">.</span><span class="n">PerformSpellCheckUsingDialog</span><span class="p">();</span> <span class="p">}</span></code></pre></div> </div> </div> </div>
NOTE
You can add multiple
OpenOfficeDictionarywith various culture files into theSfSpellChecker.Dictionariescollection. Based on theSfSpellChecker.CulturerespectiveOpenOfficeDictionaryis used for spell check.

Add custom words to dictionary
If you want to add words that is not available in existing dictionary, you can add it using CustomDictionary. This dictionary does not has a grammar file, it accepts only dictionary file that contains a list of words. Users can also add words to this custom dictionary by clicking Add to Dictionary button available in dialog or context menu.
You can add multiple CustomDictionary for each culture using SfSpellChecker.Dictionaries collection. If you load the SfSpellChecker with en-US culture, then you can add your custom words only on en-US cultured CustomDictionary.
Adding Custom Dictionary
- Create a custom dictionary text file, set build action as
Noneand setCopy to Output DirectorytoCopy if newer.

-
Create a
CustomDictionaryinstance and add the custom word file path to the CustomDictionary.DictionaryUri property and add the culture to the CustomDictionary.Culture property. -
Add the
CustomDictionaryinto theSfSpellChecker.Dictionariescollection -
Setting the required culture to the
SfSpellChecker.Cultureproperty.<Grid> <StackPanel> <TextBox Text="Ribbn illustrats the Microsoft illustrats Offce 2007 UI. Our prduct exposes most of the featres of the new UI and eeps intact winhth the Slverlight architecture. Configuring and designing the layout is very easy through XAML code. Ribbon tabs and Ribbon bars are the main client area in Ribbon. Ribbon tabs will allow your end users to navigate and find the appropriate tools for the task at hand. The Ribbon bars will contain the Ribbon tools." Name="textbox" TextWrapping="Wrap"> <!--Adding Spellchecker to the TextBox--> <syncfusion:SfSpellChecker.SpellChecker> <syncfusion:SfSpellChecker Culture="en-US" x:Name="spellChecker" EnableSpellCheck="True"> <syncfusion:SfSpellChecker.Dictionaries> <!--Adding english cultured custom dictionary--> <syncfusion:CustomDictionary DictionaryUri="E:/SpellcheckerDemo/bin/Debug/English/Custom_en-US.txt" Culture="en-US"/> <!--Adding english cultured OpenOffice dictionary--> <syncfusion:OpenOfficeDictionary DictionaryUri="/CustomSpellCheck;component/US/en-US.dic" GrammarUri="/CustomSpellCheck;component/US/en-US.aff" Culture="en-US"/> </syncfusion:SfSpellChecker.Dictionaries> </syncfusion:SfSpellChecker> </syncfusion:SfSpellChecker.SpellChecker> </TextBox> <Button Content="Spell Check" Click="SpellCheck_ButtonClick" HorizontalAlignment="Center"></Button> </StackPanel> </Grid>//Creating a culture instance CultureInfo culture = new CultureInfo("en-US"); SfSpellChecker spellChecker = new SfSpellChecker(); // Get the current PROJECT directory Uri CustomDict_uri= new Uri(Directory.GetCurrentDirectory()+ @"\English\Custom_en-US.txt", UriKind.Absolute); //Add Custom dictionary for US culture spellChecker.Dictionaries.Add( new CustomDictionary() { Culture = culture, DictionaryUri = CustomDict_uri } ); //Add US culture OpenOffice dictionary spellChecker.Dictionaries.Add( new OpenOfficeDictionary() { Culture = culture, GrammarUri = new Uri("/CustomSpellCheck;component/US/en-US.aff", UriKind.Relative), DictionaryUri = new Uri("/CustomSpellCheck;component/US/en-US.dic", UriKind.Relative) } //Setting a US culture for SpellChecker spellChecker.Culture = culture; //Assigning a spellchecker to the TextBox SfSpellChecker.SetSpellChecker(textbox, spellChecker);<div class="tabs"> <ul class="nav nav-tabs" role="tablist"> <li role="presentation" class=""><a data-target="#dsbegxu5lsmhfesabbh0a6mlxhovcz2t-csharp" aria-controls="home" role="tab" data-toggle="tab" data-original-lang="csharp">C#</a></li> </ul> <div class="tab-content"> <div role="tabpanel" class="tab-pane" id="dsbegxu5lsmhfesabbh0a6mlxhovcz2t-csharp" data-original-lang = "csharp" ><div class="highlight"><pre><code class="language-csharp" data-lang="csharp"><span></span><span class="c1">//Call SpellCheck method to open SpellCheck on button click</span> <span class="k">private</span> <span class="k">void</span> <span class="nf">SpellCheck_ButtonClick</span><span class="p">(</span><span class="kt">object</span> <span class="n">sender</span><span class="p">,</span> <span class="n">RoutedEventArgs</span> <span class="n">e</span><span class="p">)</span> <span class="p">{</span> <span class="n">spellChecker</span><span class="p">.</span><span class="n">PerformSpellCheckUsingDialog</span><span class="p">();</span> <span class="p">}</span></code></pre></div> </div> </div> </div>
NOTE
As custom dictionary hold extra words that is not available in standard dictionary, it is always used in conjunction with standard dictionary.
NOTE
If you use the custom dictionary without standard dictionary, all words that are not included in the dictionary will be shown as error words.
NOTE
You can add multiple
CustomDictionarywith various culture word files into theSfSpellChecker.Dictionariescollection. Based on theSfSpellChecker.CulturerespectiveCustomDictionaryis used for spell check.

NOTE
Switch language(Culture) at runtime
You can add Hunspell, Ispell, or OpenOffice dictionaries one or more times with various culture into the SfSpellChecker.Dictionaries collection. You can change the spell check culture at runtime by changing the SfSpellChecker.Culture property. Based on the current SfSpellChecker.Culture respective dictionary is used to spell check.
<Grid>
<StackPanel>
<TextBox
Text="Nous sommevs heureusre de vous avochir ici"
Name="textbox"
TextWrapping="Wrap">
<!--Adding Spellchecker to the TextBox-->
<syncfusion:SfSpellChecker.SpellChecker>
<syncfusion:SfSpellChecker
Culture="fr-FR"
x:Name="spellChecker"
EnableSpellCheck="True">
<syncfusion:SfSpellChecker.Dictionaries>
<!--Adding French cultured Hunspell dictionary-->
<syncfusion:HunspellDictionary DictionaryUri="/HunSpellCheck;component/French/fr-FR.dic"
GrammarUri="/HunSpellCheck;component/French/fr-FR.aff"
Culture="fr-FR"/>
<!--Adding Spanish cultured Hunspell dictionary-->
<syncfusion:HunspellDictionary DictionaryUri="/HunSpellCheck;component/Spanish/es-ES.dic"
GrammarUri="/HunSpellCheck;component/Spanish/es-ES.aff"
Culture="es-ES"/>
!--Adding english cultured Hunspell dictionary-->
<syncfusion:HunspellDictionary DictionaryUri="/HunSpellCheck;component/US/en-US.dic"
GrammarUri="/HunSpellCheck;component/US/en-US.aff"
Culture="en-US"/>
</syncfusion:SfSpellChecker.Dictionaries>
</syncfusion:SfSpellChecker>
</syncfusion:SfSpellChecker.SpellChecker>
</TextBox>
<Button
Content="Spell Check"
Click="SpellCheck_ButtonClick"
HorizontalAlignment="Center"></Button>
</StackPanel>
</Grid>SfSpellChecker spellChecker = new SfSpellChecker();
// Adding Hunspell dictonaries in Dictionaries collection
spellChecker.Dictionaries = new DictionaryCollection();
//Add French culture Hunspell dictionary
spellChecker.Dictionaries.Add(
new HunspellDictionary()
{
Culture = new CultureInfo("fr-FR"),
GrammarUri = new Uri("/HunSpellCheck;component//French/fr-FR.aff", UriKind.Relative),
DictionaryUri = new Uri("/HunSpellCheck;component//French/fr-FR.dic", UriKind.Relative)
}
);
//Add Spanish culture Hunspell dictionary
spellChecker.Dictionaries.Add(
new HunspellDictionary()
{
Culture = new CultureInfo("es-ES"),
GrammarUri = new Uri("/HunSpellCheck;component//Spanish/es-ES.aff", UriKind.Relative),
DictionaryUri = new Uri("/HunSpellCheck;component//Spanish/es-ES.dic", UriKind.Relative)
}
);
//Add US culture Hunspell dictionary
spellChecker.Dictionaries.Add(
new HunspellDictionary()
{
Culture = new CultureInfo("en-US"),
GrammarUri = new Uri("/HunSpellCheck;component//US/en-US.aff", UriKind.Relative),
DictionaryUri = new Uri("/HunSpellCheck;component//US/en-US.dic", UriKind.Relative)
}
);
//Setting a required dictionary's french culture for SpellChecker
spellChecker.Culture = spellChecker.Dictionaries[0].Culture;;
//Assigning a spellchecker to the TextBox
SfSpellChecker.SetSpellChecker(textbox, spellChecker);//Call SpellCheck method to open SpellCheck on button click
private void SpellCheck_ButtonClick(object sender, RoutedEventArgs e) {
spellChecker.PerformSpellCheckUsingDialog();
}
Here, SpellChecker.Culture is fr-FR culture. So, fr-FR cultured Hunspell dictionary is used as speck check dictionary.