0

Recently I started looking into Per Monitor DPI awareness for windows 10 and noticed that it should be supported by default as I'm using .net5.0 if there are a couple of things configured.

So I went along and followed the steps from this article: https://github.com/Microsoft/WPF-Samples/tree/master/PerMonitorDPI

And nothing happened on for the main app I've tried it.

Then I've decided to create a small sample app with a button and some text, thinking that perhaps the styling and custom stuff in the main app block something, and behold, when switching the sample app's window to my secondary monitor, the text is blurry.

Looking into the samples provided I see that there are a bunch of refresh stuff done in code behind when DPI changes, this looks a lot like "before per monitor DPI aware work-around code".

Can someone help me? What am I missing, i understood that WPF supports this out of the box on windows 10, do I still need those hundreds of lines of code to refresh everything when changing monitors?

Akos
  • 210
  • 4
  • 14
  • Have you set `PerMonitorV2` for dpiAwareness? https://learn.microsoft.com/en-us/windows/win32/hidpi/setting-the-default-dpi-awareness-for-a-process – emoacht Aug 07 '22 at 15:00
  • You will always have to manually force a redraw of the WPF application's GUI to let it adapt to the new DPI setting. Opposed to UWP, WPF does not support automatic DPI detection to redraw the GUI. UWP does behave the way you expect. The "old" WPF requires the developer to handle the redraw. – BionicCode Aug 07 '22 at 17:25
  • @BionicCode It was the case before .NET Framework 4.6.2. The adaption to Per-Monitor DPI by WPF has completed with `PerMonitorV2` when Windows 10 1703 was released. https://blogs.windows.com/windowsdeveloper/2017/04/04/high-dpi-scaling-improvements-desktop-applications-windows-10-creators-update/ Since then, a developer doesn't need to handle it manually in most cases. – emoacht Aug 08 '22 at 03:23
  • @emoacht I have not, i will check it out today and give feedback. thank you. – Akos Aug 08 '22 at 09:15

1 Answers1

1

As @emoacht has commented, using "PerMonitorV2" instead of just "PerMonitor" makes WPF applications automatically Per monitor DPI aware for Windows 10 (after a certain build number)

In case you have converted your application from an older .Net version and just changed the project to SDK Style, don't forget to mention the manifest in the project file.

enter image description here

Akos
  • 210
  • 4
  • 14