30

By default a WPF TextBlock 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 LineHeight 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

ANeves
  • 6,219
  • 3
  • 39
  • 63
Gleno
  • 16,621
  • 12
  • 64
  • 85
  • 2
    If you have an answer you should post it as such, answers do *not* belong into the question, also make sure to accept it once you are allowed to. – H.B. Sep 25 '11 at 09:04

3 Answers3

52

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. --> 
Community
  • 1
  • 1
Gleno
  • 16,621
  • 12
  • 64
  • 85
11

This is probably part of the font which is Segoe UI by default, try Segoe instead for example. (You cannot assign negative padding but you could assign negative Margins, e.g.: Margin="0,-3,0,0")

H.B.
  • 166,899
  • 29
  • 327
  • 400
6

This space is not padding, but part of the font, reserved for accents above and below characters.

The accepted answer makes the line height smaller than the font height.

Mark
  • 374
  • 4
  • 9