Is the ViewBox the best thing to use to achieve resolution independence in WPF?
Asked Answered
B

2

11

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.

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?

Biofeedback answered 4/4, 2009 at 1:41 Comment(0)
L
2

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

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

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.

Lymphocytosis answered 5/4, 2009 at 21:8 Comment(5)
resolution dependent templates? Does that mean have a template for each resolution and at run time determine which to use? That seems like a lot of work.Biofeedback
Of course not. It only means to have several layouts dependent on resolution: For example for people with 800x600 and less you only display a list, and for people with bigger displays you additionally display some extra info panel.Lymphocytosis
Photo Suru is dead link 2018-06-07Landlocked
More over Photo Sure page now looks like it's been taken over by malware.Ratsbane
<dpiAware xmlns="schemas.microsoft.com/SMI/2005/…> I want to switch it off to check how it will look on a small screen, the setting does not work for me.Slimsy
I
5

WPF has resolution independence at its core. Its default measurement is in Device Independent Pixels (DIPs), not pixels. Can you explain how this is not working for you, and perhaps provide a very simple example of XAML that is not scaling correctly?

Insignia answered 4/4, 2009 at 8:17 Comment(2)
My biggest problem has been with the fonts. Everything else I've, for the most part, been able mess around with enough to come up with some sort of layout that seems to work across resolutions. However, the screens I have done, have taken a lot of time.Biofeedback
Any general tips on how to ensure my windows display the same across resolutions? And how to hand font scaling?Biofeedback
L
2

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

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

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.

Lymphocytosis answered 5/4, 2009 at 21:8 Comment(5)
resolution dependent templates? Does that mean have a template for each resolution and at run time determine which to use? That seems like a lot of work.Biofeedback
Of course not. It only means to have several layouts dependent on resolution: For example for people with 800x600 and less you only display a list, and for people with bigger displays you additionally display some extra info panel.Lymphocytosis
Photo Suru is dead link 2018-06-07Landlocked
More over Photo Sure page now looks like it's been taken over by malware.Ratsbane
<dpiAware xmlns="schemas.microsoft.com/SMI/2005/…> I want to switch it off to check how it will look on a small screen, the setting does not work for me.Slimsy

© 2022 - 2024 — McMap. All rights reserved.