9

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.

Herrozerro
  • 1,601
  • 1
  • 22
  • 37
  • You can completely disable dpi scaling in WPF by following [disable-dpi-awareness-for-wpf-application](https://stackoverflow.com/questions/13858665/disable-dpi-awareness-for-wpf-application/44171474#44171474) – Calin Pirtea May 25 '17 at 02:54
  • You can disable dpi scaling for WPF in .net 4.5 following [disable-dpi-awareness-for-wpf-application](https://stackoverflow.com/questions/13858665/disable-dpi-awareness-for-wpf-application/44171474#44171474) – Calin Pirtea May 25 '17 at 02:55

2 Answers2

4

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

Community
  • 1
  • 1
Der_Meister
  • 4,771
  • 2
  • 46
  • 53
2

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>
Dejco
  • 21
  • 1