本文介绍了ViewBox 是在 WPF 中实现分辨率独立的最佳选择吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个需要独立于分辨率的应用程序.该应用程序将始终全屏显示,因此我必须设计我的 UI,以便显示器分辨率不会影响应用程序的使用.我已经花了很多时间来尝试使用 WPF 来实现这一目标.今天我发现了Viewbox.它似乎解决了我所有的问题.我所要做的就是将用于布局每个屏幕的网格放置在 Viewboxes 中,就像魔术一样,我有一个独立于分辨率的应用程序.

I'm developing an application that needs to be resolution independent. The application will always be full screen so I have to design my UI so that the monitor resolution will not impair the use of the application. I've been spending a good amount of time playing around with WPF trying to accomplish this. Today I found out about the Viewbox. It seems to solve all my problems. All I have to do is place the Grids used to layout each screen in Viewboxes and like magic I have a resolution independent application.

然而,这似乎很容易.感觉不太对.我应该使用 Viewboxes 吗?如果不是,我应该怎么做?在我发现 Viewbox 之前,我很难想出一种根据分辨率缩放字体大小的方法.有了 Viewbox,我就不用担心这个了.因此,如果 Viewbox 使用不当,我该如何调整文本大小?

However, this just seems to easy. It doesn't feel right. Should I be using Viewboxes? If not what should I do instead? Before I found out about the Viewbox I was having difficulty coming up with a way to scale the font sizes with respect to resolution. With a Viewbox I don't have to worry about this. So if a Viewbox is the wrong thing to use, how do I go about resizing my text?

推荐答案

实际上,您说得很对.WPF IS 与分辨率无关,但问题在于您如何控制字体大小.

Actually, you're quite right. WPF IS resolution independent, but the problem is how you control font sizing.

应该避免使用 ViewBox,因为它们具有成本效益,但我认为一个单一的不应该伤害任何人.

ViewBoxes should be avoided, because they cost performance, but I think a single one shouldn't hurt anybody.

但请注意:它现在看起来可能是这样,但是您根本无法在 640x480 下显示与 1600x1200 下一样多的信息.​​..最优雅的解决方案是使用 Photo Suru 应用程序 中演示的分辨率相关模板.

But beware: It may look right now, but you simply can't display as much information with 640x480 as with 1600x1200...The most elegant solution is to use resolution dependent templates which are demonstratet in the Photo Suru app.

这篇关于ViewBox 是在 WPF 中实现分辨率独立的最佳选择吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 16:28