WPF:如何缩放以适应内容?
它基本上是这样的: 我有一个画布容器(x:name="Container" - 稍后参考),还有一些其他控件(例如我有一个大小为 30x60 的按钮),我想缩放容器以适合按钮,而无需调整大小任何事物。 (仅使用scaleTransform) 如果我设置绑定到容器比例的滑块,我可以滑动它以适合按钮,但该值是 1.1343,我希望能够以某种方式以编程方式计算该值,因为容器内的所有控件都有不同的大小,并且另外可调整大小。 问题是:有没有办法缩放容器,以便容器中的控件显示在整个容器表面上?此外,还必须调整位置,以便容器的滚动视图应位于控件上方,但这已经完成了。
先感谢您, 丹尼尔
It gets basicaly to this:
I have a canvas container (x:name="Container" - to reffer later to), with some other controls(e.g. I have a Button 30x60 in size) and I want to scale the Container to fit the button, without having to resize anything. (just using scaleTransform)
If I set a slider binded to the Container Scale, I can slide it to fit the button, but the value is 1.1343 and I want to be able somehow to compute this value programatically, because all the controls inside Container are of different sizes, and resizable in adition.
The question is: is there a way to scale the Container so that a Control from the container is displayed on the entire Container surface? Also the position will have to be adjusted, so that the scrolling vierew of the Container should be positioned over the control, but that is done already.
Thank you in advance,
Daniel
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用Grid作为容器。放置在 Grid 内部的任何控件都会直接填充整个 Grid,并且其大小(宽度和高度)将与 Grid 的大小相匹配。
Use Grid as the container. Any control placed inside of the Grid will directly fill the whole Grid, and its size (the width and height) will match the size of the Grid.
看起来,当您使用网格作为容器添加用户控件时,由一组标签和一组按钮组成的用户控件不会与顶部对齐,而是排列在中间的某个位置。
It seems when you add a user control using a grid as a container, the usercontrol, which comprises a set of labels and an array of buttons will not align to the top but arranged somewhere in the middle.