Skip to content
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

DpiAwareness & DoNotScaleForDpiChanges not working for Windows desktop application under .NET 8 #9803

Open
vsfeedback opened this issue Sep 18, 2024 · 0 comments

Comments

@vsfeedback
Copy link

This issue has been moved from a ticket on Developer Community.


Hi,

I am having problem setting WPF window based desktop .NET 8 application to work as DpiAware and preventing automatic scaling of a window.

System default automatic scaling schema…

When user changes Windows 10 display setting scale, WPF-Window is being scaled accordingly.
Also, when window is dragged to another display, that has different scale, window is being scaled.
I want to prevent these automatic scaling because I’m using my own scaling schema.

Before .NET 8, when application was using WPF 4.8, following two items together were preventing such automatic behavior:

A) @ app.manifest

...

<application xmlns="urn:schemas-microsoft-com:asm.v3">
     <windowsSettings>
         <dpiAware xmlns="https://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
         <dpiAwareness xmlns="https://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitor</dpiAwareness>
     </windowsSettings>
 </application>

...
B) @ app.config

<?xml version="1.0" encoding="utf-8"?>
 <configuration>
     <startup> 
         <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
     </startup>
   <runtime>
     <AppContextSwitchOverrides value="Switch.System.Windows.DoNotScaleForDpiChanges=true"/>
   </runtime>
 </configuration>

Now, @ .NET 8,, that is not working anymore!

Though I found some solution that app.config file is not NET 8 compatible.

So, AppContextSwitchOverrides … Switches like…

Switch.System.Windows.DoNotScaleForDpiChanges
are transferred from

“appname”.config => “appname”.runtimeconfig.json

In order to control these switches … I had to put new item group into *.csproj

<Project>
...
<ItemGroup>
   <RuntimeHostConfigurationOption Include="Switch.System.Windows.DoNotScaleForDpiChanges" Value="true" />
   <RuntimeHostConfigurationOption Include="Switch.System.IO.UseLegacyPathHandling" Value="false" />
</ItemGroup>
...
</Project>

So, RuntimeHostConfigurationOption has done the job!

Now, if I run my WPF Application at my development Laptop which has full HD screen (1920 x 1080) run successfully and if I change the screen scaling from 125% to other option like 100%, 175% etc then my application UI is not scale according to Windows OS scaling and that the thing I want.

But if I run my application at full HD and suddenly change the Laptop screen resolution to 1366 x 768 or any other lower resolution while running the app, my WPF App UI perfectly scale and fit according to it, but if I close the application and start again at that lower resolution then it's not working somehow the Per Monitor DPI Awareness not trigger in.

The main problem is if I start my application on another display or another computer the DPI Awareness not working though I already declared it as Per Monitor DPI in the App.Manifest but it's not working. The RuntimeHostConfigurationOption code successfully prevent the scaling but the DPI Awareness is not working.


Original Comments

Nicole Hu [MSFT] on 9/18/2024, 11:15 AM:

We have converted this feedback item to a problem. This change was done to better reflect the feedback’s nature. It will allow other developers to easily find it and engage on it.

Feedback Bot on 9/18/2024, 00:39 PM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant