سؤال

I have a TextBlock, as follows:

<TextBlock Text="|e|" Padding="2" HorizontalAlignment="Center" TextWrapping="Wrap" Background="AliceBlue" />

However, this renders as a single vertical line, like so:

enter image description here

I can do any of the following and it renders as expected:

  • change the text in any way;
  • reduce the padding;
  • remove the horizontal alignment (or set it to its default, Stretch);
  • remove the text wrapping (or set it to its default, NoWrap).

(The background setter is not relevant and is included merely to show that the TextBlock appears to be allocating space for the text.)

Can anyone shed any light on this seemingly bizarre behaviour?

هل كانت مفيدة؟

المحلول

You can use: HorizontalAlignment="Stretch" TextAlignment="Center"

<TextBlock Text="|e|" Padding="2" TextWrapping="Wrap" Background="AliceBlue" HorizontalAlignment="Stretch" TextAlignment="Center" />
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top