如何在WPF中锚定控件? [英] How to anchor controls in WPF?

查看:214
本文介绍了如何在WPF中锚定控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 TreeView 填充了应用程序的顶部,但是由于 TreeView 更改,我的应用按钮会垂直更改其位置。有没有一种方法可以将其锚定在窗口的底部,因此它始终位于窗口的右底部,即距右下边缘的距离为10x10。

I have a a TreeView that fills the top part of the application, but since the number of items in the TreeView changes, my Apply button changes its position vertically. Is there a way to anchor it to the bottom part of the window, so it's always on the right bottom part of the window, i.e. 10x10 distance from the right bottom edge.

推荐答案

您可以在TreeView或Button上设置Horizo​​ntalAlignment和VerticalAlignment(我无法确定您要锚定哪个控件),也可以将控件放在DockPanel中。

You can either set the HorizontalAlignment and VerticalAlignment on the TreeView or Button (I cannot tell which control you are trying to anchor), or you could place the control inside a DockPanel.

要使控件与其他控件间隔开,请使用Margin。

To space the control away from others use the Margin.

Margin="0 0 10 10"

只会在右侧和底部提供边距

will give you the margin only on the right and bottom

我希望这可以使它更清晰:

I hope this makes it a bit clearer:

<Window>   
  <DockPanel VerticalAlignment="Stretch">
    <TreeView DockPanel.Dock="Top" />
    <Button DockPanel.Dock="Bottom" Margin="0 0 10 10" />   
  </DockPanel>
</Window>

这篇关于如何在WPF中锚定控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆