共用方式為


Control.VerticalContentAlignment 屬性

定義

取得或設定控制項內容的垂直對齊。

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; }
[<System.ComponentModel.Bindable(true)>]
member this.VerticalContentAlignment : System.Windows.VerticalAlignment with get, set
Public Property VerticalContentAlignment As VerticalAlignment

屬性值

VerticalAlignment

其中一個 VerticalAlignment 值。 預設為 Top

屬性

範例

下列範例示範如何在控制項上設定垂直內容對齊屬性。

<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

備註

除了 TopBottomCenter 之外,您還可以將 屬性設定 VerticalContentAlignmentStretch ,這會延展子項目以填滿父元素的配置空間。 如需詳細資訊,請參閱 對齊、邊界和填補概觀

此屬性只會影響範本使用 VerticalContentAlignment 屬性做為參數的控制項。 在其他控制項上,此屬性不會有任何影響。

相依性屬性資訊

識別碼欄位 VerticalContentAlignmentProperty
設定為 的中繼資料屬性 true

適用於