Поделиться через


FrameworkElement.VerticalAlignment Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Property VerticalAlignment As VerticalAlignment
public VerticalAlignment VerticalAlignment { get; set; }
<frameworkElement VerticalAlignment="verticalAlignmentValue"/>

XAML Values

  • verticalAlignmentValue
    A constant name from the VerticalAlignment enumeration, for example Top.

Property Value

Type: System.Windows.VerticalAlignment
A vertical alignment setting. The default is Stretch.

Remarks

Dependency property identifier field: VerticalAlignmentProperty

When Height and Width properties are explicitly set on an object, these measurements take layout precedent and cancel the regular effects of setting this property to Stretch.

Canvas does not use VerticalAlignment when composing layout, because Canvas is based on absolute positioning. In general, the value of VerticalAlignment is potentially treated differently by any given object that is capable of having one or more FrameworkElement derived object classes as child content.

Examples

In the following 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" ShowGridLines="True">
    <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>

The previous example produces output that resembles the following illustration.

margin and alignment example

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.