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以外, 还可以将属性设置为, 这会拉伸子元素以填充父元素的Center已分配空间。In 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 NoneNone

适用于