I've tried to add custom dictionary (*.lex format, utf-16 encode) in RichTextBox to make spellcheck, but it doesn't works. If i using such code for TextBox, it works.
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;
}
I've already added #LID1049 in dictionary, but it has no effect. Do you know how to fix this?
There are two ways adding custom dictionaries
The first custom dictionary (customwords.lex) is added in XAML
<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>
and the Second The second custom dictionary (customwords2.lex) is added in the event handler, The file is included as a resource file and compiled into the application assembly that is named 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"));
}
Does this works for you???
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.