Control.VerticalContentAlignment Property

Definition

Gets or sets the vertical alignment of the control's content.

C#
[System.ComponentModel.Bindable(true)]
public System.Windows.VerticalAlignment VerticalContentAlignment { get; set; }

Property Value

One of the VerticalAlignment values. The default is Top.

Attributes

Examples

The following example shows how to set the vertical content alignment property on a control.

XAML
<Button Name="btn8" Height="50"
        VerticalContentAlignment="Top" 
        Click="ChangeVerticalContentAlignment">
  VerticalContentAlignment
</Button>
C#
void ChangeVerticalContentAlignment(object sender, RoutedEventArgs e)
{
    if (btn8.VerticalContentAlignment == VerticalAlignment.Top)
    {
        btn8.VerticalContentAlignment = VerticalAlignment.Bottom;
        btn8.Content = "Control vertical alignment changes from top to bottom.";
    }
    else
    {
        btn8.VerticalContentAlignment = VerticalAlignment.Top;
        btn8.Content = "VerticalContentAlignment";
    }
}

Remarks

In addition to Top, Bottom, and Center, you can set the VerticalContentAlignment property to Stretch, which stretches the child element to fill the allocated layout space of the parent element. For more information, see Alignment, Margins, and Padding Overview.

This property only affects a control whose template uses the VerticalContentAlignment property as a parameter. On other controls, this property has no impact.

Dependency Property Information

Item Value
Identifier field VerticalContentAlignmentProperty
Metadata properties set to true None

Applies to

Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9