SpellCheck.CustomDictionaries 属性

定义

获取用于自定义拼写检查的词典文件位置的集合。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

属性值

IList

词典文件位置的集合。The collection of lexicon file locations.

示例

下面的示例演示如何将两个自定义字典添加到 RichTextBox 中。The following example shows how to add two custom dictionaries to a RichTextBox. 第一个自定义字典 (lex) 在 XAML 中添加。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. 若要使用 Uri 元素,必须包含系统命名空间。To use the Uri element, you have to include the System namespace.

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

第二个自定义字典 (lex) 添加到 Click 事件处理程序中。The second custom dictionary (customwords2.lex) is added in the Click event handler. 此文件包含为资源文件并编译到名为 WPFCustomDictionary 的应用程序程序集中。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

注解

自定义字典使用词典文件,这些文件是扩展名为 lex 的文本文件。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. 文件的第一行可以指定 (LCID) 的区域设置标识符。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. 有关详细信息,请参阅 区域设置 idFor 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  

若要为派生自的任何类指定一个或多个自定义字典 TextBox TextBoxBase ,请通过将文件的 URI 添加到集合来指定词典文件的位置 CustomDictionariesTo 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.

备注

使用 Insert 将文件添加到集合将 CustomDictionaries 导致异常。Using Insert to add a file to the CustomDictionaries collection causes an exception. 请改用 AddRemove 来更新集合。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. 可以通过使用包 Uri 来引用该文件。You can reference the file by using pack URIs. 有关详细信息,请参阅 WPF 中的 Pack uriFor more information, see Pack URIs in WPF.

若要启用拼写检查器,请在 SpellCheck.IsEnabled true TextBox 派生自的任何类上将或的属性设置为 TextBoxBaseTo enable the spelling checker, set the SpellCheck.IsEnabled property to true on a TextBox or on any class that derives from TextBoxBase. TextBox除了默认拼写检查器外,还使用了的所有自定义字典。All custom dictionaries for that TextBox are used in addition to the default spelling checker. 有关拼写检查器的详细信息,请参阅 SpellCheckFor more information about the spelling checker, see SpellCheck.

适用于

另请参阅