0

I edited alot in this question, because it seems this issue is diffrent then i tought.

I decided to rewrite my whole question since somthing odd is happening: Im currently embedding WPF into my C# project for it to spell check but i've stumbled onto an quite odd issue

As you can see, i have an empty RichTextBox

I embedded a WPF richtextbox 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 to odd parts begins,

[Working] Example 1: (here i load a .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 dont need to load a file, 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 dont need to load a file, i just append the string)

omschrijving.AppendText(omschrijving_temp);

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

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

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

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

In all 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 automaticly added text..

When appending text to the RichTextBox it seems to only work when its in a .RTF (richtext) format, else it just ignores the spellingcheck.

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

Mika SD
  • 1
  • 1
  • 4
  • It probably works via binding. Try to either bind it to something an init from the view model. or refresh the dependency https://www.experts-exchange.com/questions/24661355/Force-update-of-WPF-data-binding.html – eran otzap Jan 23 '19 at 12:00
  • @eranotzap i tried the following – Mika SD Jan 23 '19 at 12:21
  • (I updated the post), and it doesn't seem to work – Mika SD Jan 23 '19 at 12:28
  • Try to set `SpellCheck.IsEnabled` to `false` and then to `true`. It may also be something to do with languages, check language for the part you are inserting. As a dumb workaround you can send all text as if user would type it ([click](https://stackoverflow.com/q/3404560/1997232)). – Sinatr Jan 23 '19 at 12:28
  • @MikaSD try initializing it from the DataContext (i.e.you'r ViewModel) – eran otzap Jan 23 '19 at 12:30
  • I edited alot in this question, because it seems this issue is diffrent then i tought. – Mika SD Jan 23 '19 at 23:53

0 Answers0