- sofia.zaid_easylaser
- Posts: 2
- Joined:
TextBlock margins
Hello,
We have an element that is declared as following:
Depending on the font size there is a margin on top of the text. We would like this margin to be smaller than it currently turns out to be. How can we achieve this?
See image below:
We have an element that is declared as following:
Code: Select all
<TextBlock x:Name="SubValue" Grid.Row="2" Style="{StaticResource Style.TextBlock.Medium}" Background="Magenta" Margin="4,0,0,0" TextAlignment="Right" VerticalAlignment="Top" Text="-0.12"/>
See image below:
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: TextBlock margins
By margin do you mean the space between the number glyphs and the edge of the magenta rectangle?
Those bounds are determined by font line height, that you can adjust by using LineHeight and LineStackingStrategy properties:
Another option that allows more control is to render the background using a Border and then adjust the TextBlock margins that can even be negative:
Those bounds are determined by font line height, that you can adjust by using LineHeight and LineStackingStrategy properties:
Code: Select all
<TextBlock Text="-0.12" TextAlignment="Right" VerticalAlignment="Top" Width="100"
FontSize="30" Foreground="White" Background="Magenta"
LineHeight="30" LineStackingStrategy="BlockLineHeight"/>
Code: Select all
<Border Background="Magenta" VerticalAlignment="Top" Width="100">
<TextBlock Text="-0.12" TextAlignment="Right"
FontSize="30" Foreground="White" Margin="0,-10,0,-7" />
</Border>
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: TextBlock margins
Great, marking this post as solved.
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 44 guests