简体   繁体   English

WPF:父控件和子控件中的Horizo​​ntalAlignment和Horizo​​ntalContentAlignment如何工作?

[英]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. 我正在尝试了解HorizontalAlignmentHorizontalContentAlignment如何与父控件有关。

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中,我发现Horizo​​ntalContantAlignment “获取或设置控件内容的水平对齐方式”。 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.

相关问题 当 Horizo​​ntalAlignment 和 Horizo​​ntalContentAlignment 不起作用时,如何使 WPF 中的控件拉伸以填充可用宽度? - How can I make controls in WPF stretch to fill available width when HorizontalAlignment and HorizontalContentAlignment don't work? WPF - 家长如何知道子控件复选框的“已选中”事件? - WPF - How does Parent know of on “Checked” event for child control checkbox? 如何在WPF中以较大的层次结构在子控件和父窗口之间进行通信? - How to communicate between child control and parent window with big hierarchy in wpf? WPF 自定义控件:ViewBox 上的 HorizontalAlignment 样式设置未正确初始化 - WPF custom control: HorizontalAlignment style setting on ViewBox does not initialize correctly 在WPF中为子控件绘制父控件 - Drawing a parent control over child controls in WPF wpf 水平对齐左和拉伸? - wpf horizontalalignment left and stretch? 父控件的 WPF ContextMenu 在具有自己的 ContextMenu 的子控件上打开 - WPF ContextMenu of parent control opens on child control with own ContextMenu WPF-Horizo​​ntalAlignment行为 - WPF - HorizontalAlignment behavior 如何在wpf中从子用户控件访问父usercontrols元素? - How can I access the parent usercontrols elements from the child user control in wpf? 如何在RibbonButton中设置Horizo​​ntalContentAlignment - How to Set HorizontalContentAlignment in RibbonButton
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM