How to set margin for inner controls of WrapPanel

Posted by Andrey Tagaew on Stack Overflow See other posts from Stack Overflow or by Andrey Tagaew
Published on 2011-01-11T10:40:45Z Indexed on 2011/01/11 10:53 UTC
Read the original article Hit count: 227

Filed under:
|

Hi Guys!

I'm new in WPF and have a question. Here is an example that I'm using:

<Window x:Class="WpfApplication2.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<StackPanel>
    <WrapPanel Orientation="Horizontal"  >
        <Button Content="test1" Margin="10,0" Padding="10,10" />
        <Button Content="test2" Margin="10,0" Padding="10,10" />
        <Button Content="test3" Margin="10,0" Padding="10,10" />
        <Button Content="test4" Margin="10,0" Padding="10,10" />
        <Button Content="test5" Margin="10,0" Padding="10,10" />
    </WrapPanel>
</StackPanel>

As you can see, my wrap panel has several buttons. Each button has the same margin and padding.

The question is, is there a way of setting margin and padding for wrap panel, so each element inside the wrap panel may use it values?

This make the code shorter and let me specify Margin and Padding only one time instead of setting it for each control in the panel.

Thank you!

© Stack Overflow or respective owner

Related posts about wpf

Related posts about wpf-controls