Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Padding (left, top, right, bottom) in WPF

Tags:

c#

padding

wpf

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?

like image 802
Lukasz Madon Avatar asked Jul 24 '10 17:07

Lukasz Madon


People also ask

What is padding in WPF?

Padding represents the distance between the side of the control (which can be the margin) and its content. The content depends on the type of the control. Margin is outside the UI element, while Padding is inside it. Next Recommended Reading WPF: Textblock Vs Label.

How do you add a space between two controls in WPF?

If you do not use (for some reason) Button's Margin property, you can put transparent Separator (Transparent background color) with desired Width (or/and Height) between your controls (Buttons in your case).

What is padding in XAML?

The Padding property represents the distance between an element and its child elements, and is used to separate the control from its own content. Padding values can be specified on layout classes.

What is the difference between label and TextBlock in WPF?

Labels usually support single line text output while the TextBlock is intended for multiline text display. For example in wpf TextBlock has a property TextWrapping which enables multiline input; Label does not have this. Label has an arbitrary Content property.


1 Answers

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.

like image 192
Lunivore Avatar answered Oct 08 '22 12:10

Lunivore