The width of the background of a textblock that surrounds the text is very narrow. However, the top and bottom is very large. How do I shrink this space down? I can't do it by setting the height, and I can't attach a negative padding to it.
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock FontSize="200"
FontWeight="Bold"
Background="Black"
Foreground="White"
Text="bla bla"
HorizontalAlignment="Center">
</TextBlock>
</Grid>
You can use the Height
of the element to reduce the space at the bottom, you can combine TextWrapping
, LineHeight
and LineStackingStrategy
to adjust the space at the top of the element:
<Grid>
<TextBlock FontSize="200"
FontWeight="Bold"
Background="Black"
Foreground="White"
Text="bla bla"
Padding="0"
Margin="0"
HorizontalAlignment="Center"
TextWrapping="Wrap"
LineStackingStrategy="BlockLineHeight"
LineHeight="200"
Height="180">
</TextBlock>
</Grid>
Result:
The property you need to set is LineHeight, combined with LineStackingStrategy = "BlockLineHeight"
<TextBlock FontSize="72"
Background="Black"
Foreground="White"
FontWeight="Bold"
Text="Hello World"
LineHeight="72"
LineStackingStrategy="BlockLineHeight" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With