Showing posts with label Padding. Show all posts
Showing posts with label Padding. Show all posts

Thursday, 18 February 2010

Remove padding from TextBox in WPF

If you add the attribute

Padding="0, 0, 0, 0"

to most WPF elements e.g. <Label></Label>, the text is placed in the top left hand corner with no space between the left and top sides.  However if you try it with a TextBox element it appears to have no effect.

Fortunately as a workaround you can set the padding to have negative values.  So e.g. if I want a standard TextBox element, with standard fontsize, with no space above the text, doing something like:

Padding="0, -2, 0, 0"

Will have the desired effect.