DPI Awareness: Windows Bitmap Scaling (6.0) vs. System Aware (6.1)
This case study examines an application initially designed as DPI-Unaware, relying on Windows bitmap scaling for high-DPI displays. An update to version 6.1 unexpectedly changed its DPI awareness to System Aware, resulting in UI distortion.
Troubleshooting the Issue
The root cause is a newly included third-party component in the updated version. Despite the application's inherent DPI-Unawareness, the third-party component introduced DPI awareness.
Managing DPI Awareness
DPI awareness can be explicitly controlled within the application manifest:
<code class="language-xml"><application> <windowsSettings> <dpiAware>false</dpiAware> </windowsSettings> </application></code>
Alternatively, Windows APIs offer programmatic control:
<code class="language-csharp">SetProcessDPIAware(); GetAwarenessFromDpiAwarenessContext(GetWindowDpiAwarenessContext(hWnd));</code>
Solution
To revert to DPI-Unawareness, add <dpiAware>false</dpiAware>
to the application manifest. If a third-party component forces DPI awareness, consider adding System.Windows.Media.DisableDpiAwareness
to AssemblyInfo.cs
to override the unwanted behavior.
The above is the detailed content of Why Does My DPI-Unaware Application Suddenly Exhibit UI Distortion After Updating to System Aware?. For more information, please follow other related articles on the PHP Chinese website!