1

I have a project in UWP where I need to display the same text in a RichEditBox and in a RichTextBlock.

For some fonts (e.g. Courier), this is pretty ok and no big problems, but for other fonts (like Arial) the difference is pretty substantial. Please note that I use exactly the same code, the only difference is just the Font.

Please find an MVCE that reproduces the issue here: https://github.com/vfailla/UWPRichEditBox

How can I setup the two elements to display the text in Arial in the very same visual way?

Cristiano Ghersi
  • 1,944
  • 1
  • 20
  • 46
  • I can reproduce this issue and I have reported to the relevant team. If there is any update, I will tell you. – Faywang - MSFT Sep 27 '19 at 04:15
  • You are probably aware, but it doesn't hurt to say explicitly: `RichTextBox` and `RichTextBlock` use incompatible document rendering and manipulation models. So 1) you can't (I wish you could) use the same code for the two, only attempt to make it formatted and look as close as possible; 2) it's no surprise there are differences in text rendering. It's really awesome MSFT guys are willing to help with issues like yours, though more generic solution, e.g. a `RichTextBlock` editor could have provided a significant boost to `UWP` popularity. – DK. Oct 01 '19 at 22:42

1 Answers1

1

For some fonts (e.g. Courier), this is pretty ok and no big problems, but for other fonts (like Arial) the difference is pretty substantial. Please note that I use exactly the same code, the only difference is just the Font.

First of all, you will need to set the same CharacterSpacing of these two different controls:

m_richEditBox.CharacterSpacing = 100;
m_richTextBlock.CharacterSpacing = 100;

Then, you will need to set the same FontStretch of two controls, but here comes the issue:After a few tests I found textStretch doesn't work for RichEditBox/TextBox. And by default, the text inside look more like FontStretch.Condensed. So as a temporary workaround, you can set your RichTextBlock.FontStretch to FontStretch.Condensed:

m_richTextBlock.FontStretch = FontStretch.Condensed;

I'll consult through internal channel to report this issue, and I'll update this thread once I got any response.

Elvis Xia - MSFT
  • 10,801
  • 1
  • 13
  • 24