如何控制WPF窗口的宽高比? [英] How can I control the aspect ratio of a WPF Window?

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

问题描述

我搜索了所有对"宽高比"的引用,WPF"。 我还没有找到这个问题的答案:


如何控制WPF窗口的宽高比,因此当用户调整窗口大小时,它的执行方式与Windows Media Center相同以正常方式(单击并拖动边框或角落)?


我已经尝试将整个布局根包装在ViewBox中。 我还使用了LayoutTransform Scale X和Y以及对Window.ActualSize的绑定。 当调整窗口大小时,两者似乎都会导致窗口内容缩小或增长,但内容区域的方面
比率与窗口的宽高比不一致。


<感谢所有人。


- 迈克

解决方案

Hello Mike,


我想您应该计算窗口的宽高比,并使用相同的窗口宽高比更改内容区域。您可以对调整窗口大小,走可视树以查找内容区域做出反应,并使用
实现绑定验证。在验证中,您将重新计算内容区域的同步大小更改。也许

这篇文章
也可能对你的计算有所帮助。


祝你好运,


马丁


I searced for all references to "aspect ratio", WPF".  I have not yet found the answer to this question:

How can I control the aspect ratio of a WPF window, so it performs the same way as Windows Media Center when the user resizes the window in the normal way (click and drag a border or corner)?

I've already tried wrapping the entire layout root in a ViewBox.  I've also used LayoutTransform Scale X and Y with a binding to Window.ActualSize.  Both seem cause the window contents to shrink or grow when resizing the window, but the aspect ratio of the content area does not stay in synch with the aspect ratio of the window.

Thanks to all.

-- Mike

解决方案

Hello Mike,

I guess you should calculate the aspect ratio of your window and change the content area with the same aspect ratio of your window. You could react on resizing the window, walk the visual tree to find your content area, and implement a binding with a validation. And in the validation you do the re-calculation for the synchronous size changing of the content area. Maybe this post might also be helpful for your calculations.

Best regards,

Martin


这篇关于如何控制WPF窗口的宽高比?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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