Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Silverlight 3
 HorizontalAlignment Property

  Switch on low bandwidth view
This page is specific to
Microsoft Silverlight 3

Other versions are also available for the following:
.NET Framework Class Library for Silverlight
FrameworkElement..::.HorizontalAlignment Property

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

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)
Visual Basic (Declaration)
Public Property HorizontalAlignment As HorizontalAlignment
    Get
    Set
Visual Basic (Usage)
Dim instance As FrameworkElement
Dim value As HorizontalAlignment

value = instance.HorizontalAlignment

instance.HorizontalAlignment = value
C#
public HorizontalAlignment HorizontalAlignment { get; set; }
XAML Attribute Usage
<frameworkElement HorizontalAlignment="HorizontalAlignment"/>

Property Value

Type: System.Windows..::.HorizontalAlignment
A horizontal alignment setting, as a value of the enumeration. The default is Stretch.

Dependency property identifier field: HorizontalAlignmentProperty

When Height and Width properties are explicitly set on an object, these measurements take higher precedent during layout and will cancel the typical 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 given object that is capable of having one or more FrameworkElement objects as child content.

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 preceding example produces output that is similar to the following illustration.

margin and alignment example

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

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker