Feature/high dpi awareness#10
Conversation
erikdarlingdata
left a comment
There was a problem hiding this comment.
Thanks for the PR and for filing the issue — the High DPI fix is a real improvement and the before/after screenshots demonstrate the problem clearly.
The manifest files are great. The app.manifest approach with <dpiAwareness>PerMonitorV2</dpiAwareness> is the Microsoft-recommended way to declare DPI awareness for WPF apps. The .csproj references are correct. This is the right solution.
The P/Invoke code in both App.xaml.cs files should be removed. Here's why:
-
The Windows loader processes the manifest during
CreateProcessInternalW, before the CLR initializes or any managed code runs. By the timeOnStartup()callsEnableDpiAwareness(), PerMonitorV2 awareness is already set. -
Calling
SetProcessDpiAwareness()after the manifest has already set DPI awareness returnsE_ACCESSDENIED(documented here): "The DPI awareness is already set, either by calling this API previously or through the application (.exe) manifest." Similarly,SetProcessDpiAwarenessContext()returnsFALSEwithERROR_ACCESS_DENIED(documented here). -
The
try/catchblocks won't catch these failures — P/Invoke calls return error codes, they don't throw .NET exceptions. The catches would only fire forDllNotFoundExceptionorEntryPointNotFoundException. -
There's also a subtle marshaling issue:
SetProcessDpiAwarenessreturnsHRESULT(notBOOL), but the P/Invoke declares it asbool.E_ACCESSDENIED(0x80070005) would marshal astrue, so even if you checked the return value, it would look like success.
In short: the manifests do all the work. The ~60 lines of P/Invoke per app (enums, DllImports, EnableDpiAwareness()) are dead code that silently fails every time. Removing them keeps the fix clean and correct.
If you'd like, I can trim the P/Invoke code on my end after merge — or you can update the PR to include only the manifest changes. Either way works. The manifests themselves are good to go.
|
Done! |
|
Thanks so much Claudio (and cousin Claude)! This is a great contribution — the manifest-only approach is clean and the before/after screenshots speak for themselves. Really appreciate you taking the time to fix this for both Dashboard and Lite. You'll get credit in the upcoming release notes. 🎉 |
What does this PR do?
Fixes #9
Claude summary
I used the help of my cousin Claude.
Here is the summary of the changes made.
Which component(s) does this affect?
How was this tested?
Lite
Before:

After:

Dashboard
Before:

After:

Checklist
dotnet build -c Debug)