Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Padding on StackPanel?

I am trying to set padding of a StackPanel but there ain't such property. I tried StackPanel.Border, but there is no such property either.

Any ideas?

like image 795
Shimmy Weitzhandler Avatar asked Aug 20 '09 02:08

Shimmy Weitzhandler


People also ask

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 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.

What is StackPanel?

StackPanel is a layout panel that arranges child elements into a single line that can be oriented horizontally or vertically. By default, StackPanel stacks items vertically from top to bottom in the order they are declared. You can set the Orientation property to Horizontal to stack items from left to right.

What is margin in WPF?

The margin adds extra space around the outside edges of an element. The Margin property of FrameworkElement represents the margin of an element. It is a type of Thickness structure. The Thickness structure has the four properties Left, Top, Right and Bottom.


2 Answers

You could put a Border around the StackPanel and set a padding on that. I end up doing this a lot, since there are many UIElements that do not have a padding property.

<Border Padding="10">     <StackPanel>         <!--...-->     </StackPanel> </Border> 

(Note: all FrameworkElements have a Margin property, which will space the element, but not include the margin width as part of the ActualWidth).

If you want to space the items inside a StackPanel, you'll want to add a margin to each child as Rob said.

like image 133
Tim Swast Avatar answered Sep 23 '22 04:09

Tim Swast


Or you could do something similar to TiM:

<Border>     <StackPanel Margin="10">         ...     </StackPanel> </Border> 
like image 28
Oliver Avatar answered Sep 24 '22 04:09

Oliver