You have discovered that WPF calls SetProcessDPIAware (). This happens inside the module initializer for the PresentationCore. This is formally illegal, it must always be called before the application creates any windows or loads DLLs that can cache the DPI value. Or, in other words, there are many ways that this could go wrong, you just so far discovered its moderate version. This is usually not a problem in a pure WPF application, since PresentationCore always needs to be loaded before any window is created.
They backed up to disable this behavior. Copy / paste this code, best of all, into the AssemblyInfo.cs source file for your EXE project:
[assembly: System.Windows.Media.DisableDpiAwareness]
But this is not so important, of course, DPI virtualization is now always enabled for all your windows. Go ahead by declaring your dpi application in your manifests so that PresentationCore can't mess it up. But with the inevitable side effect, you will find that you need to fix your Winforms UI. It can decrease only when the Form.AutoScaleMode property changes or it does something unreasonable, like hard-coding the window size. The attribute is the Q & D fix.
Hans passant
source share