Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

SpellCheck.CustomDictionaries Property

.NET Framework (current version)

The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Gets the collection of lexicon file locations that are used for custom spell checking.

Namespace:   System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)

public IList CustomDictionaries { get; }

Property Value

Type: System.Collections.IList

The collection of lexicon file locations.

Custom dictionaries use lexicon files, which are text files that have a .lex extension. Each line of a lexicon file contains a single word that is accepted as a legitimate spelling. The first line of the file can specify a locale identifier (LCID) that the dictionary applies to. If the locale is not specified, the dictionary applies to all languages. For more information, see Locale IDs. The following example shows the first few lines of a lexicon file for the English language.

#LID 1033

To specify one or more custom dictionaries for a TextBox or for any class that derives from TextBoxBase, specify the location of the lexicon file by adding the URI for the file to the CustomDictionaries collection.


Using Insert to add a file to the CustomDictionaries collection causes an exception. Instead, use Add and Remove to update the collection.

The lexicon files can be included in the application as content files installed on the local computer or as resource files compiled into a local referenced assembly. You can reference the file by using pack URIs. For more information, see Pack URIs in WPF.

To enable the spelling checker, set the SpellCheck.IsEnabled property to true on a TextBox or on any class that derives from TextBoxBase. All custom dictionaries for that TextBox are used in addition to the default spelling checker. For more information about the spelling checker, see SpellCheck.

The following example shows how to add two custom dictionaries to a RichTextBox. The first custom dictionary (customwords.lex) is added in XAML. The file is included in the application as a content file and copied to the output directory. To use the Uri element, you have to include the System namespace.


The second custom dictionary (customwords2.lex) is added in the Click event handler. The file is included as a resource file and compiled into the application assembly that is named WPFCustomDictionary.

<RichTextBox Margin="38,18,40,0" Name="richTextBox1" Height="45" VerticalAlignment="Top" SpellCheck.IsEnabled="True" >
        <!-- customwords.lex is included as a content file-->
private void button1_Click(object sender, RoutedEventArgs e)
    IList dictionaries = SpellCheck.GetCustomDictionaries(richTextBox1);
    // customwords2.lex is included as a resource file
    dictionaries.Add(new Uri(@"pack://application:,,,/WPFCustomDictionary;component/customwords2.lex"));

.NET Framework
Available since 4.0
Return to top
© 2017 Microsoft