4

How could I develop resolution-independent and monitor size independent WPF apps? Monitor size independent means here suppose I develop a WPF app on a 15-inch monitor and when I will view that app on a 17-inch monitor then often UI looks different so how could I get rid of this problem in WPF? Please guide in detail. Thanks.

Sabuncu
  • 5,095
  • 5
  • 55
  • 89
Thomas
  • 33,544
  • 126
  • 357
  • 626
  • Why does the UI look different on a larger monitor? Visual elements have been able to scale up depending on the resolution of the user's screen since the very beginning. You don't need any fancy WPF features for that. What exactly do you notice changing? – Cody Gray - on strike Feb 04 '11 at 12:20
  • Resolution independent is answered below. "monitor size independent" will be quite hard to do. How can your program know if the connected monitor that runs in 1024x768 is a 15" or a 24"? The OS itself might not even know this. – Øyvind Bråthen Feb 04 '11 at 12:50

3 Answers3

10

What you are looking for is Liquid Layout in WPF.

Avoid specifying explicit Width and Height for your elements and it should scale up to whatever screen resolution available.

Of course, MinWidth, MaxWidth and MinHeight, MaxHeight are also useful in restricting the size.

Reference:

Community
  • 1
  • 1
decyclone
  • 30,394
  • 6
  • 63
  • 80
5

That's pretty complicated question. Basically, WPF was created to allow to create resolution independent application. For example, all values (width, height etc.) are in Device Independent Pixels, where each point is 1/96 of an inch (which matches one pixel per point for monitor with DPI set to 96).

But of course this will not let you create completely device independent applications. Here you need to remember to use appropriate layout mechanisms, like using DockPanel, StackPanel or Grid, and not Canvas. Your controls should be set to fill all available space (HorizontalAlignment set to Stretch), only some should have Width or Height set explicitly.

It's rather big topic, good practices, that will allow you to complete your goal are spreaded over the web and books, probably no one will be able to put it in here in short version.

Jarek
  • 3,359
  • 1
  • 27
  • 33
1

Provided the DPI for the system display is set correctly the WPF should scale the interface appropriately.

Lazarus
  • 41,906
  • 4
  • 43
  • 54
  • @Thomas: Now that I think about it I don't think I actually understand what you are asking for. So you want your buttons which appear to be, for example, 10% of the width of your screen to always be 10% of the width of the display or do you want them to always to be the same physical width, i.e. 1 inch? – Lazarus Feb 04 '11 at 12:56