开发者

Resolution independent or monitor size independent WPF apps

开发者 https://www.devze.com 2023-02-08 07:27 出处:网络
How could I develop resolution-indepe开发者_如何学编程ndent 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 v

How could I develop resolution-indepe开发者_如何学编程ndent 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.


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:

  • Automatic Layout in WPF
  • Discussion on MSDN forums on same topic with lots of pointers
  • Is WPF Really Resolution Independent?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消