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. Thickness結構本身支援字串類型轉換,好讓您可以指定非對稱MarginXAMLXAML也屬性語法。The Thickness structure itself supports string type conversion so that you can specify an asymmetric Margin in XAMLXAML attribute syntax also.

非零的邊界適用於外部項目配置的空間ActualWidthActualHeightA non-zero margin applies space outside the element layout's ActualWidth and ActualHeight.

邊界的加總的同層級項目中的版面配置。比方說,兩者皆擁有 30 的邊界設定相鄰型 edge 的兩個相鄰項目會有 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 Attribute UsageXAML 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、 頂端、 右下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" 將被解譯成表示ThicknessLeftRight設定為 20,和TopBottom設為 50。Margin="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). 您也可以藉由附加單位類型字串來指定其他單位cmin,或pt任何量值。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). 如需詳細資訊Extensible Application Markup Language (XAML)Extensible Application Markup Language (XAML)使用量,請參閱ThicknessFor more information on Extensible Application Markup Language (XAML)Extensible Application Markup Language (XAML) usage, see Thickness.

thicknessReferencethicknessReference
將現有的物件參考ThicknessAn object reference to an existing Thickness. 這可能是}、 a 或}參考。This might be a }, a , or } reference. 如需詳細資訊Extensible Application Markup Language (XAML)Extensible Application Markup Language (XAML)使用量,請參閱ThicknessFor more information on Extensible Application Markup Language (XAML)Extensible Application Markup Language (XAML) usage, see Thickness.

相依性屬性資訊Dependency Property Information

識別項欄位Identifier field MarginProperty
若要設定的中繼資料屬性 trueMetadata properties set to true AffectsMeasure

適用於

另請參閱