簡體   English   中英

如何在WPF RichTextBox中使工作自定義詞典

[英]how to make working custom dictionary in wpf richtextbox

我試圖在RichTextBox中添加自定義詞典(* .lex格式,utf-16編碼)以進行拼寫檢查,但是它不起作用。 如果我為TextBox使用此類代碼,則可以使用。

private void SpellCheckInit()
{   
    // this works            
    txt_Box.SpellCheck.CustomDictionaries.Add(new Uri(@"C:\dictionary.lex"));

    // dictionary language is russian, but this setting makes spellcheck works                  
    txt_Box.Language = System.Windows.Markup.XmlLanguage.GetLanguage("en-GB");
    txt_Box.SpellCheck.IsEnabled = true;

    // this doesn't works
    richtxt.SpellCheck.CustomDictionaries.Add(new Uri(@"C:\dictionary.lex"));
    var ruLang = System.Windows.Markup.XmlLanguage.GetLanguage("ru");
    var enLang = System.Windows.Markup.XmlLanguage.GetLanguage("en-GB");
    richtxt.Language = ruLang;

    // or richtxt.Language = enLang; there are no difference for working
    richtxt.SpellCheck.IsEnabled = true; 
}

我已經在字典中添加了#LID1049,但沒有效果。 你知道如何解決這個問題嗎?

有兩種添加自定義詞典的方式

XAML中添加了第一個自定義詞典(customwords.lex)

<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>

第二個第二個自定義詞典(customwords2.lex)被添加到事件處理程序中,該文件作為資源文件被包含並編譯到名為WPFCustomDictionary的應用程序程序集中

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"));
}

這對您有用嗎???

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM