#326 – Specifying a Symmetrical Margin Using Two Arguments
June 22, 2011 1 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 a value to be used for the left and right margins, and a value to be used for the top and bottom margins. So a value of 10,20 is identical to 10,20,10,20.
The value of 10,20 indicates that the left and right margins should both be 10 WPF units and top and bottom should both be 20. Using the two-argument version results in symmetrical margins.
“The value of 10 indicates that the left and right margins should be identical and add up to 10 WPF units.”
This is incorrect. MSDN says “Margin=”20,50″ will be interpreted to mean a Thickness with Left and Right set to 20, and Top and Bottom set to 50.”