WPF RichTextBox - Iterating through Text Words and Changing Their Content and Formatting

I have a WPF RichTextBox that contains text and images in a FlowDocument. I need to iterate over text words (those that build the text that the user sees on the screen), and change their contents and formatting. For example, change the word "room" to the word "house", applying a red color to the latter.

  • I need to change the words whether they are formatted or unformatted. For example, if the word is in italic, color, or just plain black text, it doesn't matter to me.

  • Each word will be replaced with one that has approximately the same length, so I do not want this operation to affect the overall layout of the page. All images and other objects should remain in their positions.

  • Preferably, the process of this operation is not visible to the user. Only its result should be visible (i.e. there are no visible text options).

  • If this operation can be performed either directly on the FlowDocumet, or using the RichTextBox properties / methods, then a simple one is preferable (but it will be ideal for both options).

VB code examples will be great, but C # is also welcome.

Thank you so much

+3
source share

Source: https://habr.com/ru/post/1772546/


All Articles