WPF RichTextBox - Formatting of typed text
Posted
by Alan Spark
on Stack Overflow
See other posts from Stack Overflow
or by Alan Spark
Published on 2010-04-05T10:59:38Z
Indexed on
2010/04/05
11:03 UTC
Read the original article
Hit count: 611
I am applying formatting to selected tokens in a WPF RichTextBox. To do this I get a TextRange that encompasses the token that I would like to highlight. I will then change the color of the text like this:
textRange.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Blue);
This is happening on the TextChanged event of my RichTextBox.
The formatting is applied as expected, but continuing to type text will result in the new text inheriting the formatting that has already been applied to the adjacent word. I would like the formatting of any new text to use the default formatting options defined in the RichTextBox properties. Is this possible?
Alternatively I could highlight all tokens that I don't want be blue with the default formatting options but this feels awkward to me.
© Stack Overflow or respective owner