Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 523
Dan Vogel Avatar asked Apr 04 '09 01:04

Dan Vogel


2 Answers

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?

like image 65
Kent Boogaart Avatar answered Oct 29 '22 17:10

Kent Boogaart


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.

like image 26
Hades32 Avatar answered Oct 29 '22 15:10

Hades32