#949 – Add a Custom Dictionary for Spell Checking in a TextBox

The built-in spell checker in a TextBox uses a predefined dictionary to look up words.  This means that there may be words flagged as misspelled because they are not in the dictionary.
949-001

You can add a custom dictionary to WPF’s spell checker by creating a lexicon (.lex) file.  To create a custom dictionary, start by creating a .lex file in your project.

949-002

Add any custom words to your dictionary, one line at a time.

949-003

Set the Build Action of the .lex file to Resource.

949-004

In the .xaml file containing the TextBox element, define a namespace that refers to the system assembly.

        xmlns:sys="clr-namespace:System;assembly=system"

And set the SpellCheck.CustomDictionaries element using a Uri to refer to your dictionary.

        <TextBox Name="txtMyText" Margin="5" Height="100"
                 TextWrapping="Wrap"
                 VerticalScrollBarVisibility="Auto"
                 SpellCheck.IsEnabled="True">
            <SpellCheck.CustomDictionaries>
                <sys:Uri>pack://application:,,,/MyDictionary.lex</sys:Uri>
            </SpellCheck.CustomDictionaries>
        </TextBox>

The spell checker now recognizes your custom words.

949-005

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

2 Responses to #949 – Add a Custom Dictionary for Spell Checking in a TextBox

  1. Pingback: Dew Drop – November 13, 2013 (#1666) | Morning Dew

  2. Terri Hess says:

    So now the spellchecker will recognize the words in this dictionary, and include them in the suggestions.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: