-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix setting DPI awareness #6245
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! This is definitely a mistake on my part and I believe that this is the right fix.
if (assemblyApp != null && Attribute.IsDefined(assemblyApp, typeof(System.Windows.Media.DisableDpiAwarenessAttribute))) | ||
{ | ||
// DpiAware composition is enabled for this application. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you keep the comments at the same place as the previous C++ code? You can use this code for reference:
wpf/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/main.cpp
Lines 184 to 205 in 560f243
Assembly ^ assemblyApp; | |
Type ^ disableDpiAwareType = System::Windows::Media::DisableDpiAwarenessAttribute::typeid; | |
bool bDisableDpiAware = false; | |
// By default, Application is DPIAware. | |
assemblyApp = Assembly::GetEntryAssembly(); | |
// Check if the Application has explicitly set DisableDpiAwareness attribute. | |
if (assemblyApp != nullptr && Attribute::IsDefined(assemblyApp, disableDpiAwareType)) | |
{ | |
bDisableDpiAware = true; | |
} | |
if (!bDisableDpiAware) | |
{ | |
// DpiAware composition is enabled for this application. | |
SetProcessDPIAware_Internal( ); | |
} | |
// Only when DisableDpiAwareness attribute is set in Application assembly, | |
// It will ignore the SetProcessDPIAware API call. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it it to match the original C++ code more closely. I renamed bDisableDpiAware
to disableDpiAware
, so that it matches typical C# conventions.
Currently it is only setting DPI awareness if the entry assembly has a DisableDpiAwarenessAttribute applied to it.
Description
Currently DPI awareness will be enabled only if a
DisableDpiAwarenessAttribute
attribute is applied to the entry assembly. Which does not make a lot of sense. This also does not match the behavior of .NET 6.This PR changes the logic to always enable DPI awareness unless a
DisableDpiAwarenessAttribute
attribute is applied to the entry assembly.Customer Impact
WPF applications are not DPI aware. This can be seen by:
And then checking the DPI Awareness column in Task Manager. On .NET 6 the DPI awareness is "System". In .NET 7 preview 1, it is "Unaware".
Regression
This regression was introduced by #5765, which migrated the DPI awareness enablement code from C++ to C#.
Testing
Then replace the contents of
MainWindow.xml.cs
with:Results of running this program on different versions of WPF:
Risk
Low.