SpellCheck.CustomDictionaries 屬性

定義

取得用於自訂拼字檢查之 Lexicon 檔案位置的集合。

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

屬性值

Lexicon 檔案位置的集合。

範例

下列範例示範如何將兩個 RichTextBox 自訂字典新增至 。 第一個自訂字典 (customwords.lex) 會在 XAML 中新增。 檔案會以內容檔案的形式包含在應用程式中,並複製到輸出目錄。 若要使用 Uri 元素,您必須包含 System 命名空間。

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

事件處理常式中 Click 會新增第二個自訂字典 (customwords2.lex) 。 檔案會隨附為資源檔,並編譯成名為 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 的文字檔。 語彙檔案的每一行都包含接受為合法拼字的單一字。 檔案的第一行可以指定字典套用的地區設定識別碼 (LCID) 。 如果未指定地區設定,字典會套用至所有語言。 如需詳細資訊,請參閱 地區設定識別碼。 下列範例顯示英文的語彙檔案的前幾行。

#LID 1033  
TextBlock  
TextBox  
ListBox  

若要為 TextBox 衍生自 TextBoxBase 的任何類別指定 或 一或多個自訂字典,請將檔案的 URI 新增至 CustomDictionaries 集合,以指定語彙檔案的位置。

注意

使用 Insert 將檔案新增至 CustomDictionaries 集合會造成例外狀況。 請改用 AddRemove 來更新集合。

語彙檔案可以包含在應用程式中,做為安裝在本機電腦上的內容檔,或是編譯成本機參考元件的資源檔。 您可以使用套件 URI 來參考檔案。 如需詳細資訊,請參閱 WPF 中的 Pack URI

若要啟用拼字檢查程式,請在 SpellCheck.IsEnabled 或 衍生自 TextBoxBase 的任何類別上 TextBox ,將 屬性設定為 true 。 除了預設拼字檢查程式之外,所使用的所有自訂字典 TextBox 。 如需拼字檢查程式的詳細資訊,請參閱 SpellCheck

適用於

另請參閱