When you see Margin attribute in a XAML file of WPF, it has four components. Why is this? The first two components make sense they are offset from top left window, but what is it for the third and fourth components when we have 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>
XAML ValuesMargin="20,50" will be interpreted to mean a Thickness with Left and Right set to 20, and Top and Bottom set to 50. The default unit for a Thickness measure is device-independent unit (1/96th inch). You can also specify other units by appending the unit type strings cm , in , or pt to any measure.
The Margin property of UIElement, which is parent class of all WPF controls is used to set the margin of a control. Margin property takes four numbers - Left, Top, Right and Bottom, that is margin to the left top and right bottom. This example sets Margin of a Button control in XAML at design-time.
The margin is the space between an element and the parent element or other adjacent element on the same parent element. The margin adds extra space around the outside edges of an element. The Margin property of FrameworkElement represents the margin of an element. It is a type of Thickness structure.
Padding and margin In order to ensure consistent use of whitespace throughout the application, given a component could be used in a variety of contexts, it may be best to use rem for margin and padding than em .
Margin always has four components: left, top, right and bottom. Two components are just shorthand when top=bottom and left=right. And one component is shorthand when all four components are the same.
Here is good explanation of Margins and Paddings.
The margin can be different on all sides of an element. Therefore the four elements are:
Margin="left,top,right,bottom"
refer here:
http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.margin.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With