0

Recently I found that uwp render TextBlock with vertically margin in default.

For example, I wrap a TextBlock in a Border. The red rectangle maybe the safe space redered by TextBlock.

On Android, we can set

android:includeFontPadding="false"

So how to remove the red rectangle space on uwp?

enter image description here

Vincent
  • 3,124
  • 3
  • 21
  • 40

2 Answers2

0

As i understand you want this, and Didn't you tried this ?:

<Border BorderThickness="1" BorderBrush="GreenYellow">
   <TextBlock x:Name="tb" FontSize="48" Text="Color" Margin="0,-15,0,-10"/>
   <Border.RenderTransform>
      <ScaleTransform ScaleX="1" ScaleY="3" />
   </Border.RenderTransform>
 </Border>

Output

Output

Shubham Sahu
  • 1,963
  • 1
  • 17
  • 34
  • Thanks for your reply. The red rectangle area I marked is the space created by Text itself. On Android, we can set 'android:includeFontPadding="false"'. Is there a property in uwp? – Vincent Feb 26 '20 at 03:32
0

Finally I worked out a solution: Set

<TextBlock LineStackingStrategy="BlockLineHeight"
           LineHeight="44"/>

Refer to How to remove additional padding from a WPF TextBlock?

Vincent
  • 3,124
  • 3
  • 21
  • 40