Export (0) Print
Expand All

SpellCheck.CustomDictionaries Property

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
TextBlock
TextBox
ListBox

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.

NoteNote

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.

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

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" >
    <SpellCheck.CustomDictionaries>
        <!-- customwords.lex is included as a content file-->
        <sys:Uri>pack://application:,,,/customwords.lex</sys:Uri>
    </SpellCheck.CustomDictionaries>
</RichTextBox>
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

Supported in: 4.6, 4.5, 4

.NET Framework Client Profile

Supported in: 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft