Chris Ward
Chris Ward

Reputation: 718

Strange WPF TextBlock Behaviour

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:

(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?

Upvotes: 0

Views: 156

Answers (1)

Igor Koval
Igor Koval

Reputation: 46

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

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

Upvotes: 1

Related Questions