Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Have a WPF Application ignore DPI settings

Tags:

c#

dpi

wpf

I have a wpf application that is designed for a 1900x1200 resolution but some of our users have used the windows display settings to resize everything by 125%-150%, is there a way to have an application ignore those settings and still display normally?

I have seen something called SetProcessDPIAware here, but havent had any luck with it.

Here is a screen shot of the application with the display scaling turned up to 150% Application with Scaling

As you can see the application is way too small and there is no way to get it to be correctly sized.

like image 912
Herrozerro Avatar asked Aug 26 '13 17:08

Herrozerro


2 Answers

Dpi awareness will not help in this case. It will only change CompositionTarget.TransformToDevice matrix, but controls sizes will not change.

I use view box to scale all content. All sizes in my app are designed for Surface Pro 3 portrait:

<Window>
    <Viewbox Stretch="Uniform">
        <Grid Width="1440" Height="2160">
            <!-- ... -->
        </Grid>
    </Viewbox>
</Window>

You can calculate view box size basing on screen DPI. See this answer: https://stackoverflow.com/a/12414433/991267

like image 92
Der_Meister Avatar answered Oct 14 '22 02:10

Der_Meister


New way to ignore dpi is:

Right click on your project

Add > New item

Find "Application Manifest File (Windows Only)

Uncomment at line 55, or find dpiAware

  <application xmlns="urn:schemas-microsoft-com:asm.v3">
    <windowsSettings>
      <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
      <longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
    </windowsSettings>
  </application>
like image 21
Dejco Avatar answered Oct 14 '22 03:10

Dejco