views:

1707

answers:

4

Hello folks!

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?

A: 

Could it be Margin you are looking for?

benPearce
+1  A: 

You'll probably want to add margin to the items in the panel instead. You'll get the same result, just have to approach it backward.

Rob
+5  A: 

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.

Tim Swast
+1  A: 

Or you could do something similar to TiM:

<Border>
<StackPanel Margin=10>
...
</StackPanel>
</Border>
Oliver