DPI Unaware Application Suddenly Became System Aware: Troubleshooting Guide
This document addresses a scenario where a previously DPI-Unaware application unexpectedly transitioned to DPI-System Aware mode without code changes. This shift disrupts the application's reliance on Windows virtualization for scaling.
The Problem: An application, previously operating as DPI Unaware, now exhibits DPI System Aware behavior.
Likely Cause: The most probable cause is the introduction of a DPI-Aware dependency, either directly or indirectly. Referencing DPI-Aware components can trigger inheritance of their DPI Awareness setting.
Resolution Strategies:
Several methods can restore the application's DPI Unaware status:
Explicitly Disable DPI Awareness (AssemblyInfo.cs): Add the following attribute to your AssemblyInfo.cs
file to override any inherited DPI Awareness settings:
<code class="language-csharp">[assembly: System.Windows.Media.DisableDpiAwareness]</code>
App Manifest Configuration: In your application manifest file, explicitly set DPI Unaware mode:
<code class="language-xml"><dpiaware>false</dpiaware></code>
Windows API Approach: Use appropriate Windows API functions to set the process's DPI Awareness context:
SetProcessDPIAware()
SetProcessDpiAwareness()
or SetProcessDpiAwarenessContext()
SetProcessDpiAwarenessContext()
with DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED
for optimal compatibility.Per-Thread DPI Awareness (If Needed): For more granular control, consider using SetThreadDpiAwarenessContext()
to manage DPI Awareness on a per-thread basis. This approach is generally less preferred unless absolutely necessary.
By implementing one of these solutions, you should be able to revert your application to its intended DPI Unaware behavior and resolve the scaling issues. Consider testing thoroughly after implementing each method.
The above is the detailed content of Why Did My DPI-Unaware Application Suddenly Become DPI-System Aware?. For more information, please follow other related articles on the PHP Chinese website!