[英]WPF: How works HorizontalAlignment and HorizontalContentAlignment in parent and child control?
I am trying to understand how HorizontalAlignment
and HorizontalContentAlignment
will work with regard to parent control. 我正在尝试了解
HorizontalAlignment
和HorizontalContentAlignment
如何与父控件有关。
For example, here is simple code: 例如,下面是简单的代码:
<StatusBar VerticalAlignment="Bottom" Width="600" HorizontalContentAlignment="Right" HorizontalAlignment="Left">
<Label Margin="5">StatusBar</Label>
</StatusBar>
I suppose that the Label will appear at the right side of the StatusBar, because in MCTS 70-511 book I found that HorizontalContantAlignment "Gets or sets the horizontal alignment of the control's content." 我想标签会出现在StatusBar的右侧,因为在MCTS 70-511中,我发现HorizontalContantAlignment “获取或设置控件内容的水平对齐方式”。 Isn't the Label is a content in my case?
标签不是我的内容吗? If it is not, so what is?
如果不是,那是什么?
I have tried to add HorizontalAlignment="Right"
to my Label but it made no changes. 我试图将
HorizontalAlignment="Right"
添加到我的Label中,但未做任何更改。
Moreover, what will happen if my parent control has HorizontalContentAligment="Left"
and the content of it will has HorizontalContentAligment="Right"
? 此外,如果我的父控件具有
HorizontalContentAligment="Left"
并且其内容将具有HorizontalContentAligment="Right"
怎么办? Child's property will "cover" the one from parent? 孩子的财产会“覆盖”父母的财产吗?
HorizontalAlignment="Right"
- This will change the Alignment for the Control. HorizontalAlignment="Right"
-这将更改控件的对齐方式。 HorizontalContentAligment="Left"
- This Will change the Alignment for the Content based on its parent. HorizontalContentAligment="Left"
-这将基于其父项更改内容的对齐方式。
In your code, StatusBar
will be set to Left alignment based on its parent. 在您的代码中,
StatusBar
将基于其父项设置为“左对齐”。
Label
will be set to Right based on the StatusBar
. Label
将基于StatusBar
设置为Right。
http://msdn.microsoft.com/en-us/library/vstudio/aa970569(v=vs.100).aspx http://msdn.microsoft.com/zh-CN/library/vstudio/aa970569(v=vs.100).aspx
With the reference of the above like, StatusBar
wasnt use the HorizontalContentAligment
Property in its Control Template, so it will not reflect in your Code. 参照上述类似内容,
StatusBar
在其控件模板中未使用HorizontalContentAligment
属性,因此它不会反映在您的代码中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.