I am quite new to WPF and have come across a problem.
I have a rich text box and I set it's text. Then, whenever the rich texbox text changes (using event handler), I need to check if it was equal to the origional text.
But, even when the text hasn't changed, the code says it has due to a new line appearing when reading the text.
This is basically what I am doing: (a simiplified version showing the problem)
//Create a new text box
RichTextBox r = new RichTextBox();
//Write Text "Hello World" to the rich text box
r.Document.Blocks.Clear();
r.Document.Blocks.Add(new Paragraph(new Run("Hello World")));
//Read Text "Hello World" from rich text box
string textBoxText = new TextRange(r.Document.ContentStart, r.Document.ContentEnd).Text;
Console.WriteLine("\"" + textBoxText + "\"");
I would expect to see "Hello World" in the console, but instead it gives:
"Hello World
"
Because there is a new line after this, it causes problems in my code. Is there a better way of reading and writing the RichTextBox to avoid this??