1

I'm currently embedding WPF into my C# project for it to spell check, but I've stumbled onto quite an odd issue.

As you can see, I have an empty RichTextBox

I embedded a WPF rich text box to C# like this:

System.Windows.Controls.RichTextBox richTextBox1 = new System.Windows.Controls.RichTextBox();

elementHost1.Child = richTextBox1;
omschrijving.SpellCheck.IsEnabled = true;

Now here is where the odd part begins:

[Working] Example 1: (here I load an .rtf file into my textbox)

TextRange range = new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd);
FileStream stream = new FileStream("file_example.rtf", FileMode.Create, FileAccess.Write, FileShare.None);
range.Load(stream, DataFormats.Rtf);
stream.Close();

[Not working] Example 2: (here I load a .txt file into my textbox)

TextRange range = new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd);
FileStream stream = new FileStream("file_example.txt", FileMode.Create, FileAccess.Write, FileShare.None);
range.Load(stream, DataFormats.Text);
stream.Close();

[Not working] Example 3: (here I don't load a file, because I don't need to, instead I just pass the string)

new System.Windows.Documents.TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text = omschrijving_temp;

[Not working] Example 4: (here I don't load a file, because I don't need to, instead I just append the string)

omschrijving.AppendText(omschrijving_temp);

Example 1 loads the text into the RichTextBox, and then shows red dots on the text (spelling errors).

Example 2 loads the text into the RichTextBox, and then ignores the spelling check.

Example 3 loads the text into the RichTextBox, and then ignores the spelling check.

Example 4 loads the text into the RichTextBox, and then ignores the spelling check.

In all the examples above, when I type in the RichTextBox (after the text is appended), the spelling check works perfectly, but it ignores the spelling check for the automatically added text.

When appending text to the RichTextBox it seems to work only when it's in a .RTF (richtext) format; otherwise it just ignores the spelling check.

Is there any fix, is this a bug? or?

ImNoSTN
  • 11

0 Answers0