Q:

Monospace Margin between elements in WPF

I want the space between the child elements in, for example, StackPanel be the same. When using the same Margin for child elements, gap between neighbors doubles. I'm using a little trick to solve this, but it seems to me there is more elegant solution. May be you have one?
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="MyButtonStyle" TargetType="Button">
    <Setter Property="Margin" Value="4,4,0,4" />
    ...
</Style>
<Style x:Key="LastMyButtonStyle" TargetType="Button" BasedOn="{StaticResource MyButton}">
    <Setter Property="Margin" Value="4" />
</Style>

I'm using MyButtonStyle for all buttons except the last one, which use LastMyButtonStyle.

A:

Put the StackPanel in another container, i.e. a Border, and set its Margin to the same value as those of the Buttons:
<Border>
    <StackPanel Orientation="Horizontal" Margin="2">
        <Button Margin="2" Content="Button 1"/>
        <Button Margin="2" Content="Button 2"/>
        <Button Margin="2" Content="Button 3"/>
    </StackPanel>
</Border>

