Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content
Switch branches/tags
Go to file
Cannot retrieve contributors at this time
-api-id -api-type
winrt property



Gets or sets the horizontal alignment characteristics that are applied to a FrameworkElement when it is composed in a layout parent, such as a panel or items control.


<frameworkElement HorizontalAlignment="horizontalAlignmentMemberName"/>


horizontalAlignmentMemberNameA constant name from the HorizontalAlignment enumeration, for example Left.
## -property-value A horizontal alignment setting, as a value of the enumeration. The default is **Stretch**.


Alignment properties are intended to hint the desired layout to an adaptive layout container. They're typically set on FrameworkElement children and interpreted by another FrameworkElement container parent (typically a ContentControl derived class or a Panel derived class, or perhaps a presenter). Setting alignment properties on a child element is no guarantee that anything happens; the behavior depends on the layout composition and the parent elements involved.

When the Height and Width properties are explicitly set or calculated on an object, those measurements are more important to typical layout logic, and can cancel the effects of setting HorizontalAlignment to Stretch. Layout constraint properties (such as MaxWidth) also affect the maximum or minimum layout size for a Stretch layout situation. Stretch is the default so that it's easier to use adaptive layout techniques in the cases where there is no explicit measurement. But if there are either Height and Width or clipping, the layout acts as if the value is Top for VerticalAlignment, typically Left for HorizontalAlignment (Right for right-to-left culture info or explicit FlowDirection values). For more info, see Alignment, margin, and padding.

Canvas does not use HorizontalAlignment when composing layout, because Canvas is based on absolute positioning. In general, the value of HorizontalAlignment is potentially treated differently by any object that is capable of having one or more FrameworkElement objects as child content. Each such parent object can have its own layout logic.

Each XAML UI element might apply this property differently based on the Style setters for the implicit style. The apparent "default value" for HorizontalAlignment in each UI element can be different. For example, a Button control starts with the value Left. If the UI element is a control, the HorizontalAlignment value might also affect the control's visual template.

In content controls, the control template often uses {TemplateBinding} markup extension expressions to bind the HorizontalContentAlignment property to a HorizontalAlignment property on some element within its template, such as the presenter or the element used as the content area.


In this example, the value Center is assigned to HorizontalAlignment and VerticalAlignment, to position the TextBlock elements in the center of the Grid cells.



Width, VerticalAlignment, Alignment, margin, and padding