FrameworkElement.HorizontalAlignment 属性

定义

获取或设置在父元素(如 Panel 或项控件)中组合此元素时所应用的水平对齐特征。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.

public:
 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.

注解

在元素上显式设置 HeightWidth 属性时,这些度量值会在布局中获得更高的引用单元格,并取消将 HorizontalAlignment 设置为 Stretch的典型效果。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.

HorizontalAlignmentMicrosoft .NETMicrosoft .NET 属性访问器,对于实际上是依赖属性。HorizontalAlignment 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. 例如,Label 控件的 HorizontalAlignment 的外观 "默认" 将 Left,即使 LabelHorizontalAlignment 继承 FrameworkElement直接。For 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

适用于