WPF:如何缩放以适应内容? [英] WPF: How can i scale to fit the content?

查看:68
本文介绍了WPF:如何缩放以适应内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它基本上是这样的:我有一个画布容器(x:name="Container" - 稍后参考),还有一些其他控件(例如,我有一个 30x60 大小的按钮),我想缩放容器以适合按钮,而无需调整大小任何事物.(仅使用 scaleTransform)如果我设置一个绑定到 Container Scale 的滑块,我可以滑动它以适合按钮,但值是 1.1343,我希望能够以某种方式以编程方式计算该值,因为 Container 内的所有控件都具有不同的大小,并且另外可调整大小.问题是:有没有办法缩放容器,以便容器中的控件显示在整个容器表面上?此外,必须调整位置,以便容器的滚动视图应位于控件上方,但这已经完成了.

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.

先谢谢你,丹尼尔

推荐答案

使用 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.

这篇关于WPF:如何缩放以适应内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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