#326 – Specifying a Symmetrical Margin Using Two Arguments
June 22, 2011 Leave a comment
You can set the Margin property on a control so that it has some extra room around its edges, within its container.
You can specify a value for the Margin property in XAML using either one, two or four integer values. Using one value indicates the margin for each of the four sides of the control. Using four values indicates the left/top/right/bottom margin values individually.
When you use two values in specifying the Margin, you are specifying the combined left-right and top-bottom margins. I.e. Margin=”left+right, top+bottom“.
<StackPanel>
<Label Content="Gene Autry the singing cowboy" Background="Pink" />
<Button Content="I Like Gene" Margin="10,20"/>
<Label Content="Roy Rogers" Background="Aqua" />
</StackPanel>
The value of 10 indicates that the left and right margins should be identical and add up to 10 WPF units. Using the two-argument version results in symmetrical margins.
