Control.VerticalContentAlignment Control.VerticalContentAlignment Control.VerticalContentAlignment Control.VerticalContentAlignment Property

定義

取得或設定控制項內容的垂直對齊。Gets or sets the vertical alignment of the control's content.

public:
 property System::Windows::VerticalAlignment VerticalContentAlignment { System::Windows::VerticalAlignment get(); void set(System::Windows::VerticalAlignment value); };
[System.ComponentModel.Bindable(true)]
public System.Windows.VerticalAlignment VerticalContentAlignment { get; set; }
member this.VerticalContentAlignment : System.Windows.VerticalAlignment with get, set
Public Property VerticalContentAlignment As VerticalAlignment

屬性值

其中一個 VerticalAlignment 值。One of the VerticalAlignment values. 預設為 TopThe default is Top.

範例

下列範例會示範如何在控制項上設定內容的垂直對齊方式屬性。The following example shows how to set the vertical content alignment property on a control.

<Button Name="btn8" Height="50"
        VerticalContentAlignment="Top" 
        Click="ChangeVerticalContentAlignment">
  VerticalContentAlignment
</Button>
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";
    }
}
Private Sub ChangeVerticalContentAlignment(ByVal Sender As Object, ByVal e As RoutedEventArgs)

    If (btn8.VerticalContentAlignment = VerticalAlignment.Top) Then

        btn8.VerticalContentAlignment = VerticalAlignment.Bottom
        btn8.Content = "Control vertical alignment changes from top to bottom."

    Else

        btn8.VerticalContentAlignment = VerticalAlignment.Top
        btn8.Content = "VerticalContentAlignment"
    End If
End Sub

備註

除了TopBottom,並Center,您可以設定VerticalContentAlignment屬性設Stretch,這會自動縮放以填滿父項目的已配置版面配置空間的子項目。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.

這個屬性只會影響的控制項的範本會使用VerticalContentAlignment屬性做為參數。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

識別項欄位Identifier field VerticalContentAlignmentProperty
若要設定的中繼資料屬性 trueMetadata properties set to true None

適用於