Control.HorizontalContentAlignment 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置控件内容的水平对齐方式。
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 值之一。 默认值为 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
注解
除了 Left、 Right和 Center之外,还可以将 属性设置为 StretchHorizontalContentAlignment ,这将拉伸子元素以填充父元素的分配空间。 有关详细信息,请参阅 对齐、边距和填充概述。
此属性仅影响其模板使用 HorizontalContentAlignment 属性作为参数的控件。 在其他控件上,此属性没有影响。
依赖项属性信息
标识符字段 | HorizontalContentAlignmentProperty |
元数据属性设置为 true |
无 |