FrameworkElement.HorizontalAlignment property

This topic has not yet been rated - Rate this topic

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.

Syntax

Public Property HorizontalAlignment As HorizontalAlignment
   Get
   Set

<frameworkElement HorizontalAlignment="horizontalAlignmentMemberName"/>
 


XAML Values

horizontalAlignmentMemberName

A constant name from the HorizontalAlignment enumeration, for example Left.

Property value

Type: HorizontalAlignment

A horizontal alignment setting, as a value of the enumeration. The default is Stretch.

Remarks

When the Height and Width properties are explicitly set on an object, those measurements are more important to typical layout logic, and can cancel the effects of setting HorizontalAlignment to Stretch.

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 and has its own layout logic.

Examples

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


<Grid x:Name="LayoutRoot" Background="Coral" Width="300" Height="100">
    <Grid.ColumnDefinitions>
        <ColumnDefinition />
        <ColumnDefinition />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition />
    </Grid.RowDefinitions>
    <TextBlock Grid.Column="0" Grid.Row="0" Text="First Name" 
        HorizontalAlignment="Center" VerticalAlignment="Center" />
    <TextBlock Grid.Column="0" Grid.Row="1" Text="Last Name" 
        HorizontalAlignment="Center" VerticalAlignment="Center" />
    <TextBox Grid.Column="1" Grid.Row="0" />
    <TextBox Grid.Column="1" Grid.Row="1" />

</Grid>


Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Namespace

Windows.UI.Xaml
Windows::UI::Xaml [C++]

Metadata

Windows.winmd

See also

FrameworkElement

 

 

Build date: 1/31/2013

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.