4

Do WPF applications normally scale correctly on high DPI screens out of the box (without further customisation of a manifest etc?). It was my understanding they did?

Two WPF applications I have written both appear blurry on my new laptop (running Windows 10) when viewed on the laptop screen. Normally the laptop has it's primary display set to be an external low-dpi monitor and the built-in laptop panel is scaling at 125%. However, the blurriness appears regardless of whether the low-dpi monitor is plugged in or not.

I thought it might have something to do with the way my two applications launch (via a main method, rather than the default code template that launches a primary window), but I've just fired up Visual Studio 2015 and generated a brand new WPF application with the project template (just a couple of radio buttons on a blank form) and it doesn't scale into high DPI on my system either.

It may also be worth mentioning that I have configured the "prefer external manifest" registry setting on my copy of windows to allow per-application disabling of high-dpi scaling with a manifest. (i.e. HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\SideBySide "PreferExternalManifest"=dword:00000001 ).

Daniel Scott
  • 1,758
  • 16
  • 13

3 Answers3

5

Starting with .net 4.6.2 WPF apps are per Monitor DPI aware by default, not in earlier version:

WPF applications are now enabled for per-monitor DPI awareness. This improvement is critical for scenarios where multiple displays of varying DPI level are attached to a single machine. As all or part of a WPF application is transitioned between monitors, the expected behavior is for WPF to automatically match the DPI of the app to the screen. It now does. In previous versions, you would have to write additional native code to enable per-monitor DPI awareness in WPF applications.

So install the .4.6.2 dev tools and target your application to 4.6.2 to get support for this.

magicandre1981
  • 27,895
  • 5
  • 86
  • 127
3

Any program that depends on PresentationCore is automatically DPI aware. It takes an attribute to explicitly disable that.

You are surely having a different problem, a WPF app does not automatically support per-monitor dpi-awareness. A feature available since Windows 8.1. Having the primary display on an external monitor makes that very likely, you probably gave it a different DPI setting and now windows on your laptop's screen are forced to use that same DPI setting unless they explicitly opt-in. Takes a fair amount of gritty work. Or consider to simply make your laptop's screen the primary display, it is easy to switch back-and-forth with the Display applet.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Hi Hans - thanks for your answer. It seems that adding multi-monitor support is what I would need to do. It's interesting that disconnecting the low dpi (external) monitor didn't clear the rendering up earlier when I tried it - but then I guess I was just missing the step of restarting the machine (or logging out at least) after disconnecting the monitor. Setting the laptop screen to be the primary display didn't fix the fuzzy rendering either - until I restarted (windows warns you that some applications will not respond to scaling changes until logout when you change the primary display). – Daniel Scott Aug 30 '16 at 04:18
  • 1
    4.6.2 makes WPF applications per monitor aware by default according to Microsoft. See my answer – magicandre1981 Aug 30 '16 at 04:20
1

Assuming you are running a high enough version (4.6.2 according to another answer), the following does it. I am running it shortly after Window.Current.Activate():

  double GetDpi()
    {
        var qualifiers = Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView().QualifierValues;
        double scale = 96;
        if (qualifiers.ContainsKey("Scale"))
        {
            string strScale = qualifiers["Scale"];
            double.TryParse(strScale, out scale);
        }
        return scale;
    }
William Jockusch
  • 26,513
  • 49
  • 182
  • 323