如何在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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要实现锚定,请设置以下属性:
例子:
To achieve anchoring, Set following properties:
Example:
您可以在 TreeView 或 Button 上设置 HorizontalAlignment 和 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.
To space the control away from others use the Margin.
will give you the margin only on the right and bottom
I hope this makes it a bit clearer:
我认为您在按钮的 XAML 中需要这个:
I think you need this in the XAML of your button: