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

定义

获取或设置在父元素(如 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某个元素上显式设置了和属性时, 这些度量值将在布局期间获得更高的引用单元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 , FrameworkElement HorizontalAlignment Label控件的外观 "默认"为,即使从直接继承。Left LabelFor 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

适用于