FrameworkElement.Margin FrameworkElement.Margin FrameworkElement.Margin FrameworkElement.Margin Property

定义

获取或设置元素的外边距。Gets or sets the outer margin of an element.

public:
 property System::Windows::Thickness Margin { System::Windows::Thickness get(); void set(System::Windows::Thickness value); };
public System.Windows.Thickness Margin { get; set; }
member this.Margin : System.Windows.Thickness with get, set
Public Property Margin As Thickness

属性值

提供元素的边距值。Provides margin values for the element. 默认值是所有属性都等于 0(零)的 ThicknessThe default value is a Thickness with all properties equal to 0 (zero).

注解

边距是在布局创建用户界面 (UI)user interface (UI)时此元素和其他将为相邻元素之间的空间。The margin is the space between this element and other elements that will be adjacent when layout creates the 用户界面 (UI)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.

Margin设置为Thickness结构而不是数字, 以便能够以非对称方式设置边距。Margin is set as a Thickness structure rather than as a number so that the margin can be set asymmetrically. 结构本身支持字符串类型转换, 因此也可以在特性语法中XAMLXAML同时指定非对称MarginThicknessThe Thickness structure itself supports string type conversion so that you can specify an asymmetric Margin in XAMLXAML attribute syntax also.

非零边距应用元素布局和ActualWidth ActualHeight的外部空间。A non-zero margin applies space outside the element layout's ActualWidth and ActualHeight.

对于布局中的同级元素, 边距是累加的;例如, 如果两个相邻的元素在相邻边缘上都设置为 30, 则它们之间的空间间距将为60。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.

如果为边距和元素内容区域分配的矩形空间不够大, Margin则具有边距集的元素通常不会限制指定的大小。Elements that have margins set will not typically constrain the size of the specified Margin 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.

XAML 属性用法XAML Attribute Usage

<object Margin="left,top,right,bottom"/>  

-or-

<object Margin="left,top"/>  

-or-

<object Margin="thicknessReference"/>  

XAML 属性元素用法XAML Property Element Usage

<object>  
  <object.Margin>  
    <Thickness Left="left" Top="top" Right="right" Bottom="bottom"/>  
  </object.Margin>  
</object>  

XAML 值XAML Values

左、上、右、下left, top, right, bottom
值介于0和PositiveInfinity之间的数值, 用于指定Thickness结构的四个可能的维度属性。Number values between 0 and PositiveInfinity that specify the four possible dimension properties of a Thickness structure.

属性用法还会接受以对称方式和逻辑方式应用的顺序应用的缩略值。The attribute usage will also accept abbreviated values that apply in the order provided, symmetrically and logically. 例如, Margin="20"将解释为Thickness , 其所有属性都设置为20。For instance, Margin="20" will be interpreted to mean a Thickness with all properties set to 20. Margin="20,50"Thickness将解释为Bottom Top , 并将设置为20,并将设置为50。Right LeftMargin="20,50" will be interpreted to mean a Thickness with Left and Right set to 20, and Top and Bottom set to 50.

Thickness度量值的默认单位是与设备无关的单位(1/96 英寸)device-independent unit (1/96th inch)The default unit for a Thickness measure is 与设备无关的单位(1/96 英寸)device-independent unit (1/96th inch). 还可以通过将单元类型字符串cm inpt任何度量值追加到来指定其他单位。You can also specify other units by appending the unit type strings cm, in, or pt to any measure.

作为属性提供的XAMLXAML数字值不需要指定小数点 (0 是可接受的, 无需作为0.0 提供)。Number values provided as XAMLXAML attributes need not specify decimal points (0 is acceptable, does not have to be provided as 0.0). 有关可扩展应用程序标记语言 (XAML)Extensible Application Markup Language (XAML)使用情况的详细信息, Thickness请参阅。For more information on 可扩展应用程序标记语言 (XAML)Extensible Application Markup Language (XAML) usage, see Thickness.

thicknessReferencethicknessReference
对现有Thickness的的对象引用。An object reference to an existing Thickness. 这可能是}、或}引用。This might be a }, a , or } reference. 有关可扩展应用程序标记语言 (XAML)Extensible Application Markup Language (XAML)使用情况的详细信息, Thickness请参阅。For more information on 可扩展应用程序标记语言 (XAML)Extensible Application Markup Language (XAML) usage, see Thickness.

依赖项属性信息Dependency Property Information

标识符字段Identifier field MarginProperty
元数据属性设置为trueMetadata properties set to true AffectsMeasure

适用于

另请参阅