34

What I want to have is a button with a bit of left and right padding. I can set the MinWidth to some val, but if the Content will be changed it may not be enough.

 <Button MinWidth="75" Padding="2" Content="It speaks!" />

Is it possible to simulate something like Padding.left/right in WPF?

James Newton-King
  • 48,174
  • 24
  • 109
  • 130
Lukasz Madon
  • 14,664
  • 14
  • 64
  • 108

2 Answers2

81

I believe both Margins and Padding work with Thickness, which can either be described as a single integer or as a list of four: Padding="3, 10, 30, 10" for instance.

The order is left, top, right, bottom - which is annoyingly not the same as CSS.

Lunivore
  • 17,277
  • 4
  • 47
  • 92
  • 19
    you can probably remember it this way. Both are clockwise, css starts at top (top, right, bottom, left), wpf starts at left (left, top, right, bottom). That said, i agree that it's annoyingly inconsistent. css is the standard, not wpf. – liang Jun 23 '15 at 04:12
11

I'm not familiar with WPF but I think it can be

<Button MinWidth="75" Padding="left,top,right,bottom" Content="It speaks!" />

So for 2 left padding, 3 top, 4 right, and 5 bottom:

<Button MinWidth="75" Padding="2,3,4,5" Content="It speaks!" />
Jim Balter
  • 16,163
  • 3
  • 43
  • 66
Semas
  • 869
  • 10
  • 22
  • 9
    Wouldn't it be nice if it had the same order as CSS? Unfortunately it doesn't - it's left, top, right, bottom. Heaven forbid that Microsoft should ever support an established standard. – Lunivore Jul 24 '10 at 18:20
  • 1
    True, but it's rare that Microsoft do in a way everyone would like to. – Semas Jul 24 '10 at 18:22
  • 19
    To be fair to Microsoft, they're using a ordering convention they created back in the Win32 days - LONG before CSS was around. CSS is the new kid on the block in this case, not Microsoft. – 17 of 26 Jan 26 '11 at 15:54
  • 8
    Clocks have been around for longer than this though. And they go "top, right, bottom, left", same as CSS. – Lunivore Feb 27 '13 at 14:33
  • 1
    @Lunivore: Yes, but Cartesian coordinates go x-before-y – Ben Voigt May 04 '14 at 04:17
  • 1
    @BenVoigt It's not a coordinate; it's a border. It has four values, not two. At the very least I would expect it to follow the order of polar coordinates: right, top, left, bottom. Even if they followed cartesian I would expect to do all x before y, lowest first: left, right, bottom, top - or highest first: right, left, top, bottom - or even with the y starting at the top the way graphics do it: left, right, top, bottom - but all of these would involve following any kind of established conventional standard, which... well... it's Microsoft. – Lunivore May 04 '14 at 17:02