如何使控件在 WPF 中调整大小相当于 Windows 窗体的锚点/停靠属性? [英] How to make controls resize in WPF equivalently to Windows Form's anchor/dock properties?

查看:30
本文介绍了如何使控件在 WPF 中调整大小相当于 Windows 窗体的锚点/停靠属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了很多解决此问题的方法.他们每个人都无法解决我的问题.无论我将控件放入哪个容器或在控件/容器上设置什么属性,它都不会让步.我有一个带有控件的滚动查看器.当用户在运行时调整窗口大小时,我希望它随窗口调整大小.我只需要anchor=top, bottom, left, right.我不明白为什么这在 WPF 中如此难以捉摸,以及为什么需要涉及容器对象和各种属性分配来完成 Windows 窗体中单个属性的功能.但是这个问题的每个解决方案仍然导致我的控件在运行时调整窗口大小时保持在其设计时大小.在 WPF 中掌握动态控件大小的简单方法是什么?

I've read so many solutions to this problem. Every one of them fails to solve my problem. No matter what container I put the control into or what properties I set on the control/container it will not budge. I have a scroll viewer with a control within. I want it to resize with the window when the user resizes it at runtime. All I need is anchor=top, bottom, left, right. I don't understand why this is so elusive in WPF and why container objects and all kinds of property assignments need to be involved to accomplish what a single property can in Windows Forms. But every solution to this problem still results in my control staying at exactly its design time size as the window is resized at runtime. What's the simple way to get a grip on dynamic control sizing in WPF?

推荐答案

这也让我感到悲伤,而 AlexK 帮助我看到了曙光.诀窍是不要设置高度和宽度....将它们设置为 AUTO 并使用 MARGIN 来设置大小.将 HORIZONTALIGNMENTVERTICALALIGNMENT 设置为 STRETCH,然后锚点功能就起作用了.

This has caused me grief as well and AlexK helped me see the light. The trick is NOT to set the Height and Width.... Set these to AUTO and use the MARGIN to set the size. Set the HORIZONTALALIGNMENT and VERTICALALIGNMENT to STRETCH and then the anchor functionality works.

这篇关于如何使控件在 WPF 中调整大小相当于 Windows 窗体的锚点/停靠属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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