Gets or sets the outer margin of an element. This is a dependency property.
Assembly: PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
public function get Margin () : Thickness public function set Margin (value : Thickness)
<object> <object.Margin> <Thickness Left="left" Top="top" Right="right" Bottom="bottom"/> </object.Margin> </object>
<object Margin="left,top,right,bottom"/> - or - <object Margin="left,top"/> - or - <object Margin="thicknessReference"/>
The margin is the space between this element and other elements that will be adjacent when layout creates the user interface (UI). Shared elements might be peer elements (such as other elements in the collection of a common parent control), or might also be this element's parent.
is set as a Thickness structure rather than as a number so that the margin can be set asymmetrically. The Thickness structure itself supports string type conversion so that you can specify an asymmetric in XAML attribute syntax also.
Margins are additive for sibling elements in a layout; for example, two adjacent elements both with a margin of 30 set on the adjoining edge would have 60 units of space between them.
Elements that have margins set will not typically constrain the size of the specified if the allotted rectangle space is not large enough for the margin plus the element content area. The element content area will be constrained instead when layout is calculated. The only case where margins would be constrained also is if the content is already constrained all the way to zero.
This example describes how to set the property, by changing any existing property value for the margin in code-behind. The property is a property of the FrameworkElement base element, and is thus inherited by a variety of controls and other elements. For the complete sample, see Setting Margins Sample.
This example is written in Extensible Application Markup Language (XAML), with a code-behind file that the XAML refers to. The code-behind is shown in both a C# and a Microsoft Visual Basic .NET version.
For the complete sample, see Setting Margins Sample.
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.