FrameworkElement.HorizontalAlignment FrameworkElement.HorizontalAlignment FrameworkElement.HorizontalAlignment FrameworkElement.HorizontalAlignment Property


取得或設定套用至此元素在父項元素 (例如面板或項目控制項) 中組成時的水平對齊特性。Gets or sets the horizontal alignment characteristics applied to this element when it is composed within a parent element, such as a panel or items control.

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


此水平對齊方式設定作為列舉值。A horizontal alignment setting, as a value of the enumeration. 預設為 StretchThe default is Stretch.


Height專案Width上明確設定和屬性時, 這些度量會在版面配置期間佔用較高的值, 並且會取消HorizontalAlignmentStretch設定為的一般效果。When Height and Width properties are explicitly set on an element, these measurements take higher precedent during layout and will cancel the typical effects of setting HorizontalAlignment to Stretch.

HorizontalAlignment實際上是相依性屬性的屬性存取子。Microsoft .NETMicrosoft .NETHorizontalAlignment is the Microsoft .NETMicrosoft .NET property accessor for what is in reality a dependency property. 這個特定的相依性屬性經常會在子類別化的元素中以不同的方式設定其明顯的「預設」值, 特別是控制項。This particular dependency property quite frequently has its apparent "default" value set differently in subclassed elements, particularly controls. 這通常會發生在下列兩種情況中: 相依性屬性會重新註冊至特定子類別, 但使用不同的中繼資料來設定其預設值。或者, 會套用預設樣式, 以不同的方式設定該相依性屬性的值。This generally occurs in one of two ways: the dependency property is re-registered to a particular subclass, but with different metadata for setting its defaults; or there is a default style being applied that sets that dependency property value differently. 例如, 即使直接繼承HorizontalAlignment Left LabelHorizontalAlignment , 控制項的明顯「預設」還是Label 會是。FrameworkElementFor example, the apparent "default" of HorizontalAlignment for a Label control will be Left, even though Label inherits HorizontalAlignment direct from FrameworkElement. 這是因為在樣式的控制項範本內Label, 該值是在的預設樣式中重設。This is because that value was reset within the default style of Label, within the style's control template.

Canvas在撰寫版面HorizontalAlignment配置時不會使用Canvas , 因為是以絕對位置為基礎。Canvas does not use HorizontalAlignment when composing layout, because Canvas is based on absolute positioning.

當繼承Label自或衍生類別時Label , 將Left這個相依性屬性的預設值重新定義為。When inherited by Label or derived classes, Label redefines the default value of this dependency property to be Left.

相依性屬性資訊Dependency Property Information

識別碼欄位Identifier field HorizontalAlignmentProperty
中繼資料屬性設定為trueMetadata properties set to true AffectsArrange