Control.HorizontalContentAlignment Control.HorizontalContentAlignment Control.HorizontalContentAlignment Control.HorizontalContentAlignment Property

定義

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

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; }
member this.HorizontalContentAlignment : System.Windows.HorizontalAlignment with get, set
Public Property HorizontalContentAlignment As HorizontalAlignment

屬性值

範例

下列範例顯示如何設定控制項的水準內容對齊屬性。The following example shows how to set the horizontal content alignment property of a control.

<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

備註

除了LeftRightHorizontalContentAlignment Stretch之外, 您還可以將屬性設定為, 這會將子專案伸展以填滿父元素的配置空間。 CenterIn addition to Left, Right, and Center, you can set the HorizontalContentAlignment property to Stretch, which stretches the child element to fill the allocated space of the parent element. 如需詳細資訊, 請參閱對齊、邊界和填補總覽For more information, see Alignment, Margins, and Padding Overview.

此屬性只會影響其範本使用HorizontalContentAlignment屬性做為參數的控制項。This property only affects a control whose template uses the HorizontalContentAlignment property as a parameter. 在其他控制項上, 此屬性不會有任何影響。On other controls, this property has no impact.

相依性屬性資訊Dependency Property Information

識別碼欄位Identifier field HorizontalContentAlignmentProperty
中繼資料屬性設定為trueMetadata properties set to true None

適用於