共用方式為


Control.HorizontalContentAlignment 屬性

定義

取得或設定控制項內容的水平對齊。

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

屬性值

HorizontalAlignment

其中一個 HorizontalAlignment 值。 預設為 Left

屬性

範例

下列範例示範如何設定控制項的水準內容對齊屬性。

<Button Name="btn7" 
        HorizontalContentAlignment="Left"
        Click="ChangeHorizontalContentAlignment">
  HorizontalContentAlignment
</Button>
void ChangeHorizontalContentAlignment(object sender, RoutedEventArgs e)
{
    if (btn7.HorizontalContentAlignment == HorizontalAlignment.Left)
    {
        btn7.HorizontalContentAlignment = HorizontalAlignment.Right;
        btn7.Content = "Control horizontal alignment changes from left to right.";
    }
    else
    {
        btn7.HorizontalContentAlignment = HorizontalAlignment.Left;
        btn7.Content = "HorizontalContentAlignment";
    }
}
Private Sub ChangeHorizontalContentAlignment(ByVal Sender As Object, ByVal e As RoutedEventArgs)

    If (btn7.HorizontalContentAlignment = HorizontalAlignment.Left) Then

        btn7.HorizontalContentAlignment = HorizontalAlignment.Right
        btn7.Content = "Control horizontal alignment changes from left to right."

    Else

        btn7.HorizontalContentAlignment = HorizontalAlignment.Left
        btn7.Content = "HorizontalContentAlignment"
    End If
End Sub

備註

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

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

相依性屬性資訊

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

適用於