简体   繁体   English

Windows 10高DPI屏幕上的WPF应用程序模糊

[英]WPF Application Blurry on High DPI Screen on Windows 10

Do WPF applications normally scale correctly on high DPI screens out of the box (without further customisation of a manifest etc?). WPF应用程序是否可以在开箱即用的DPI高屏幕上正常缩放(无需进一步定制清单等?)。 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. 在笔记本电脑屏幕上查看时,我编写的两个WPF应用程序在新笔记本电脑(运行Windows 10)上均显得模糊。 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%. 通常,笔记本电脑的主要显示器设置为外部低dpi显示器,并且内置笔记本电脑面板的缩放比例为125%。 However, the blurriness appears regardless of whether the low-dpi monitor is plugged in or not. 但是,无论是否插入了低dpi监视器,都会出现模糊。

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. 我认为这可能与我的两个应用程序的启动方式有关(通过主方法,而不是启动主窗口的默认代码模板),但是我刚刚启动了Visual Studio 2015并生成了一个全新的WPF带有项目模板的应用程序(只是空白表单上的几个单选按钮),它在我的系统上也无法扩展为高DPI。

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. 值得一提的是,我已经在Windows副本上配置了“首选外部清单”注册表设置,以允许每个应用程序禁用清单的高dpi缩放。 (ie HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\SideBySide "PreferExternalManifest"=dword:00000001 ). (即HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\SideBySide "PreferExternalManifest"=dword:00000001 )。

Starting with .net 4.6.2 WPF apps are per Monitor DPI aware by default, not in earlier version: .net 4.6.2开始,默认情况下,每个Monitor DPI都知道WPF应用程序,而不是早期版本:

WPF applications are now enabled for per-monitor DPI awareness. 现在已启用WPF应用程序,以使每个监视器都能了解DPI。 This improvement is critical for scenarios where multiple displays of varying DPI level are attached to a single machine. 对于将不同DPI级别的多个显示器连接到一台计算机的方案,此改进至关重要。 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. 由于WPF应用程序的全部或部分在监视器之间转换,因此WPF的预期行为是将应用程序的DPI自动匹配到屏幕。 It now does. 现在可以了。 In previous versions, you would have to write additional native code to enable per-monitor DPI awareness in WPF applications. 在以前的版本中,您将不得不编写其他本机代码以在WPF应用程序中启用每个监视器的DPI感知。

So install the .4.6.2 dev tools and target your application to 4.6.2 to get support for this. 因此,请安装.4.6.2开发工具,并将您的应用程序定位到4.6.2,以获得对此的支持。

Any program that depends on PresentationCore is automatically DPI aware. 任何依赖于PresentationCore的程序都会自动识别DPI。 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. 您肯定有其他问题,WPF应用程序不会自动支持每个显示器的dpi意识。 A feature available since Windows 8.1. 从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. 在外部显示器上使用主显示器非常有可能,您可能给了它不同的DPI设置,现在笔记本电脑屏幕上的窗口被迫使用相同的DPI设置,除非它们明确选择加入。 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. 或考虑简单地将笔记本电脑的屏幕作为主要显示屏,使用“显示”小程序可以轻松地来回切换。

Assuming you are running a high enough version (4.6.2 according to another answer), the following does it. 假设您正在运行足够高的版本(根据另一个答案为4.6.2),则将执行以下操作。 I am running it shortly after Window.Current.Activate(): 我在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;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM