Margins and padding are used to add space around and inside view items. Margins and padding are always available regardless of the layout type, and are configured by setting pixel values for Left, Top, Right, and Bottom.
Spacing is used with FlowLayout, and is used to add space between child elements in a vertical or horizontal flow. Spacing is a good way to create space in text, for example.
The following example shows the effect of setting margins, padding, and spacing.
<Content>
<ColorFill Content="Blue" >
<Layout>
<!-- Spacing is used to create distance between the child elements that follow. -->
<FlowLayout Orientation="Vertical" ItemAlignment="Center" Spacing="30,30"/>
</Layout>
<Children>
<!-- No margins and no padding. -->
<ColorFill Content="Goldenrod" >
<Children>
<ColorFill Content="White" >
<Layout>
<FlowLayout Orientation="Vertical" ItemAlignment="Center"/>
</Layout>
<Children>
<Text Content="No margins, no padding" Color="Firebrick" Font="Tahoma,12"/>
</Children>
</ColorFill>
</Children>
</ColorFill>
<!-- Margins and no padding. -->
<ColorFill Content="Goldenrod" >
<Children>
<ColorFill Content="White" Margins="5,5,5,5" Padding="0,0,0,0" >
<Layout>
<FlowLayout Orientation="Vertical" ItemAlignment="Center"/>
</Layout>
<Children>
<Text Content="Margins, no padding" Color="Firebrick" Font="Tahoma,12"/>
</Children>
</ColorFill>
</Children>
</ColorFill>
<!-- No margins and some padding. -->
<ColorFill Content="Goldenrod" >
<Children>
<ColorFill Content="White" Margins="0,0,0,0" Padding="5,5,5,5" >
<Layout>
<FlowLayout Orientation="Vertical" ItemAlignment="Center" />
</Layout>
<Children>
<Text Content="Padding, no margins" Color="Firebrick" Font="Tahoma,12" />
</Children>
</ColorFill>
</Children>
</ColorFill>
<!-- Margins and padding. -->
<ColorFill Content="Goldenrod" >
<Children>
<ColorFill Content="White" Margins="5,5,5,5" Padding="5,5,5,5">
<Layout>
<FlowLayout Orientation="Vertical" ItemAlignment="Center" />
</Layout>
<Children>
<Text Content="Margins and padding" Color="Firebrick" Font="Tahoma,12" />
</Children>
</ColorFill>
</Children>
</ColorFill>
<!-- Negative margins and no padding. -->
<ColorFill Content="Goldenrod" >
<Children>
<ColorFill Content="White" Margins="-5,-5,-5,-5" Padding="0,0,0,0" >
<Layout>
<FlowLayout Orientation="Vertical" ItemAlignment="Center" />
</Layout>
<Children>
<Text Content="Neg margins, no padding" Color="Firebrick" Font="Tahoma,12" />
</Children>
</ColorFill>
</Children>
</ColorFill>
</Children>
</ColorFill>
</Content>
Sample Explorer
See Also