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

时间:2016-08-30 01:06:11

标签: c# wpf windows-10 highdpi

WPF应用程序通常可以在开箱即用的高DPI屏幕上正确缩放(无需进一步定制清单等吗?)。我理解他们做了什么?

我在笔记本电脑屏幕上查看的两台WPF应用程序在我的新笔记本电脑(运行Windows 10)上看起来都很模糊。通常情况下,笔记本电脑的主要显示器设置为外部低dpi监视器,内置笔记本电脑面板的缩放比例为125%。但是,无论是否插入低dpi监视器,都会出现模糊现象。

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

值得一提的是,我已经配置了"更喜欢外部清单"我的Windows副本上的注册表设置允许每个应用程序禁用清单的高dpi缩放。 (即HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\SideBySide "PreferExternalManifest"=dword:00000001)。

3 个答案:

答案 0 :(得分:3)

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.

答案 1 :(得分:1)

依赖于PresentationCore的任何程序都可以自动识别DPI。它需要an attribute to explicitly disable that

您肯定遇到了不同的问题,WPF应用程序不会自动支持每个监视器的dpi-awareness。自Windows 8.1以来可用的功能。将主显示器放在外部显示器上非常可能,您可能会给它一个不同的DPI设置,现在笔记本电脑屏幕上的窗口被强制使用相同的DPI设置,除非他们明确选择加入。 Takes a fair amount of gritty work。或者考虑简单地将笔记本电脑的屏幕作为主显示屏,可以轻松地使用显示小程序来回切换。

答案 2 :(得分:1)

假设您运行的版本足够高(根据另一个答案,为4.6.2),以下操作。我在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;
    }