SpellCheck.CustomDictionaries Property

Definition

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

public:
 property System::Collections::IList ^ CustomDictionaries { System::Collections::IList ^ get(); };
public System.Collections.IList CustomDictionaries { get; }
member this.CustomDictionaries : System.Collections.IList
Public ReadOnly Property CustomDictionaries As IList

Property Value

The collection of lexicon file locations.

Examples

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"));
}
Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
    Dim dictionaries As IList = SpellCheck.GetCustomDictionaries(richTextBox1)
    ' customwords2.lex is included as a resource file
    dictionaries.Add(New Uri("pack://application:,,,/WPFCustomDictionary;component/customwords2.lex"))
End Sub

Remarks

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.

Note

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.

Applies to

See also