Why does the Margin Margin attribute have four components and not two?

When you see the Margin attribute in a WPF XAML file, it has four components. Why is this? The first two components make sense that they are offset from the upper left window, but what is it for the third and fourth components, when we have the width and height?

<Grid> <Button Content="Button" Height="27" HorizontalAlignment="Left" Margin="29,27,0,0" Name="clickButton" VerticalAlignment="Top" Width="86" Click="clickButton_Click" /> <TextBox Height="27" HorizontalAlignment="Left" Margin="29,90,0,0" Name="textBoxOut" VerticalAlignment="Top" Width="276" /> </Grid> 
+7
source share
3 answers

Margin always has four components: left, top, right and bottom. The two components are only shorthand when top = bottom and left = right. And one component is an abbreviation when all four components are the same.

Here is a good explanation of the margins and shims.

+14
source

Fields can be different on all sides of an element. Therefore four elements:

 Margin="left,top,right,bottom" 

see here:

http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.margin.aspx

+13
source

When specifying a field in XAML, you can specify 1, 2, or 4 parameters.

If you specify 1 (for example, Margin="10" ), this value will be applied to all sides.

If you specify 2 (for example, Margin="10, 20" ), the first value will be applied left and right, and the second value will be applied to the upper and lower.

If you specify 4 (for example, Margin="10,20,30,40" ), the first value will be applied to the left side, the second value will be applied to the top, the third to the right, and then the fourth to the bottom.

+6
source

All Articles