SystemParameters与DPI

对于固定大小宽高的wpf程序,
如果在低分屏上能够全屏显示,由于高分屏比低分屏大,那么在高分屏上只能占高分屏的一部分,无法沾满整个屏幕。
但是这对于程序来说体验就很差,
windows可以自动处理这个问题,有几个选项。

DPI Awareness Mode Windows Version Introduced Application's view of DPI Behavior on DPI change
Unaware N/A All displays are 96 DPI Bitmap-stretching (blurry)
System Vista All displays have the same DPI (the DPI of the primary display at the time the current user session was started) Bitmap-stretching (blurry)
Per-Monitor 8.1 The DPI of the display that the application window is primarily located on • Top-level HWND is notified of DPI change
• No DPI scaling of any UI elements.
Per-Monitor V2 Windows 10 Creators Update (1703) The DPI of the display that the application window is primarily located on • Top-level and child HWNDs are notified of DPI change
Automatic DPI scaling of:
• Non-client area
• Theme-drawn bitmaps in common controls (comctl32 V6)
• Dialogs (CreateDialog)

首先:
Windows Presentation Foundation (WPF)应用程序自动感知 DPI,无需
选择加入。选择加入此设置的 Windows 窗体应用程序(目标设定为 .NET Framework 4.6 )还应
在其 app.config 中将 "EnableWindowsFormsHighDpiAutoResizing" 设置设置为 "true"。
因此WPF程序是不需要特意设置dpiAware就可以自动缩放。

所以如果我们在一个wpf程序中使用SystemParameters获取屏幕宽高的时候,实际的尺寸为真正的尺寸*缩放比率

posted @ 2021-05-10 11:48  猝不及防  阅读(296)  评论(0)    收藏  举报