I’ve searched the Internet high and low so any help the community could lend is mighty appreciated.
Is there a way to change and even reset all formatting (bold, colors, etc.) in a Paragraph object within a RichTextBox from code behind? I have a RichTextBox that I’m applying syntax and error highlighting to lines (each line represented by a Paragraph) and I want to be able to revert or change the formatting in place so TextPointers to selected text can be reselected seamlessly. For example I want to be able to do bracket matching much like Visual Studio does without the user having their caret appear at the beginning or end of a line.
Am I thinking about this in the wrong way?
This answer almost gets me there.
Thanks in advance!
The key thing to know is that the
TextRangeconstructor takes twoTextPointerobjects as start and end. Those objects don’t have to be tied to the selection in any way, and they have methods likeGetPositionAtOffsetto move through the content.Here’s some sample code to reset the font family, bold, and italic in the paragraph where the user’s caret is, without changing the selection at all: