Windows 10 上高 DPI 屏幕上的 WPF 应用程序模糊
WPF Application Blurry on High DPI Screen on Windows 10
WPF 应用程序是否通常开箱即用地在高 DPI 屏幕上正确缩放(无需进一步自定义清单等?)。我的理解是他们这样做了?
我编写的两个 WPF 应用程序在我的新笔记本电脑 (运行 Windows 10) 的笔记本电脑屏幕上查看时都显得模糊。通常笔记本电脑的主显示器设置为外部低 dpi 显示器,内置笔记本电脑面板缩放比例为 125%。但是无论是否插入低dpi显示器,都会出现模糊。
我认为这可能与我的两个应用程序的启动方式有关(通过主要方法,而不是启动主要 window 的默认代码模板),但我刚刚启动Visual Studio 2015 年并使用项目模板生成了一个全新的 WPF 应用程序(空白表单上只有几个单选按钮),它也不会在我的系统上扩展到高 DPI。
可能还值得一提的是,我已经在我的 windows 副本上配置了 "prefer external manifest" 注册表设置,以允许每个应用程序使用清单禁用高 dpi 缩放。 (即 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\SideBySide "PreferExternalManifest"=dword:00000001
)。
任何依赖 PresentationCore 的程序都会自动识别 DPI。需要 an attribute to explicitly disable that.
您肯定遇到了不同的问题,WPF 应用程序不会自动支持每个显示器的 dpi 感知。自 Windows 8.1 以来可用的功能。将主显示器放在外接显示器上很有可能,您可能为其设置了不同的 DPI 设置,现在笔记本电脑屏幕上的 windows 被迫使用相同的 DPI 设置,除非他们明确选择加入。 Takes a fair amount of gritty work。或者考虑简单地将笔记本电脑的屏幕设为主显示屏,使用显示小程序可以轻松来回切换。
从 .net 4.6.2 开始,默认情况下 WPF 应用程序是每个监视器 DPI 感知的,而不是早期版本:
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.
因此请安装 .4.6.2 开发工具并将您的应用程序定位到 4.6.2 以获得对此的支持。
假设你是 运行 一个足够高的版本(根据另一个答案是 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;
}
WPF 应用程序是否通常开箱即用地在高 DPI 屏幕上正确缩放(无需进一步自定义清单等?)。我的理解是他们这样做了?
我编写的两个 WPF 应用程序在我的新笔记本电脑 (运行 Windows 10) 的笔记本电脑屏幕上查看时都显得模糊。通常笔记本电脑的主显示器设置为外部低 dpi 显示器,内置笔记本电脑面板缩放比例为 125%。但是无论是否插入低dpi显示器,都会出现模糊。
我认为这可能与我的两个应用程序的启动方式有关(通过主要方法,而不是启动主要 window 的默认代码模板),但我刚刚启动Visual Studio 2015 年并使用项目模板生成了一个全新的 WPF 应用程序(空白表单上只有几个单选按钮),它也不会在我的系统上扩展到高 DPI。
可能还值得一提的是,我已经在我的 windows 副本上配置了 "prefer external manifest" 注册表设置,以允许每个应用程序使用清单禁用高 dpi 缩放。 (即 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\SideBySide "PreferExternalManifest"=dword:00000001
)。
任何依赖 PresentationCore 的程序都会自动识别 DPI。需要 an attribute to explicitly disable that.
您肯定遇到了不同的问题,WPF 应用程序不会自动支持每个显示器的 dpi 感知。自 Windows 8.1 以来可用的功能。将主显示器放在外接显示器上很有可能,您可能为其设置了不同的 DPI 设置,现在笔记本电脑屏幕上的 windows 被迫使用相同的 DPI 设置,除非他们明确选择加入。 Takes a fair amount of gritty work。或者考虑简单地将笔记本电脑的屏幕设为主显示屏,使用显示小程序可以轻松来回切换。
从 .net 4.6.2 开始,默认情况下 WPF 应用程序是每个监视器 DPI 感知的,而不是早期版本:
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.
因此请安装 .4.6.2 开发工具并将您的应用程序定位到 4.6.2 以获得对此的支持。
假设你是 运行 一个足够高的版本(根据另一个答案是 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;
}