Gleno Gleno - 6 months ago 40
C# Question

How to remove additional padding from a WPF TextBlock?

By default a WPF

seems to have additional top and bottom padding applied. I wish this wasn't so.

  • I've tried setting negative padding, but got an exception:

    0,-10,0,0' is not a valid value for property 'Padding'.

  • I've tried setting the
    property, to no apparent effect.

This is how the TextBlock looks in Blend. I've marked the problematic portion with maroon red.

the red area should be removed


Some research and H.B. guided me to the right answer, which is setting the following properties:

<TextBlock LineStackingStrategy="BlockLineHeight"
           LineHeight="20"/> <!-- Or some other value you fancy. -->