0

This code snippet comes from RichEditBox style application,

Document.Selection.SetRange(paragraphStartIndex, paragraphStartIndex + data.Text.Length);
Document.Selection.CharacterFormat.Strikethrough = FormatEffect.On;

However, can we do similar things with a RichTextBlock?

I know that I can add a <run> or a <Span> and add style information to these elements, but is there any way to grab the whole RichTextBlock content and apply style to a range of text within it?

Pratyay
  • 1,291
  • 14
  • 23
Skynet094
  • 443
  • 4
  • 19

1 Answers1

1

RichTextBlock and RichEditBox are rich text-related controls, but they are very different in display.

The process of RichEditBox displaying rich text is like drawing on paper, because it carries the modified function, so there is a complete Document as a carrier.

RichTextBlock is not responsible for modification, it is only responsible for display, so it is more like building blocks. RichTextBlock has a lot of display elements to render different visual effects, but they are independent of each other. You can't set effects for a certain character. You can only set the effect for the entire block (such as Paragraph).

When you select text in the RichTextBlock, you can get the parent element of the currently selected text point through RichTextBlock.SelectionStart.Parent or RichTextBlock.SelectionEnd.Parent, and set the effect.

Best regards.

Richard Zhang
  • 7,523
  • 1
  • 7
  • 13