无法让 NotifyIcon 为 DPI 缩放加载高 DPI 资源 >= 150%

Can't get NotifyIcon to load high DPI resource for DPI scaling >= 150%

我的应用程序是 DPI 感知的,这是完整的清单:

<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly xmlns:asmv1="urn:schemas-microsoft-com:asm.v1"
                manifestVersion="1.0">
    <assemblyIdentity name="SlackUI"
                      type="win32"
                      version="1.0.0.0" />
    <asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
        <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
            <dpiAware>true</dpiAware>
        </asmv3:windowsSettings>
    </asmv3:application>
</asmv1:assembly>

我正在这样设置 NotifyIcon 图标 属性:

notifyIcon.Icon = new Icon(Program.Settings.Data.WhiteNotificationIcon ?
                Properties.Resources.NotifyWhite : Properties.Resources.NotifyColor, SystemInformation.SmallIconSize)

但是,这不适用于我的 Windows 8.1 系统上等于或高于 150% 的 DPI 缩放。当它设置为 100% SystemInformation.SmallIconSize 时报告 16x16 大小(正确),当它设置为 125% 时报告 20x20 大小(正确),高于此值时,例如 150%,它应该报告 24x24 大小但报告 16x16并从我的图标文件加载了错误的分辨率。

阅读以下文章 (http://blog.quppa.net/2011/01/07/small-icon-size-dpi-in-windows/) 它告诉我...

Both WPF and WinForms wrap around the Win32 GetSystemMetrics function taking the arguments SM_CXSMICON (small icon width) and SM_CYSMICON (small icon height).

这意味着可能不需要自己给 GetSystemMetrics 打电话,对吧?

知道如何解决这个问题吗?

P.S:我说的是我正在开发的开源应用程序,所以如果您想仔细查看完整的源代码,可以这样做 here .

Strong hint that your manifest is not in fact doing its job

不是。来自您的 github SlackUI/SlackUI.csproj 文件:

<ItemGroup>
  <None Include="app.manifest">
    <SubType>Designer</SubType>
  </None>
</ItemGroup>

应该的样子是:

<PropertyGroup>
  <ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>

请注意高度特定的 <ApplicationManifest> 元素,这是让 MSBuild 知道这应该是可执行文件的清单所必需的。我通过将您的版本粘贴到 .csproj 文件中来测试您的版本,构建然后使用文件 + 打开 + 文件,select bin/Debug 目录中的 .exe 文件。打开 RT_MANIFEST 节点并双击资源 #1。它只是编译器自动生成的默认值,而不是来自 app.manifest 文件的修改后的值。

所以这就是它不起作用的原因。我不知道这是怎么发生的,也许你是手工添加的。您可以通过在解决方案资源管理器 window 中右键单击 app.manifest 并删除它来修复它。现在使用 Project > Add New Item > General > Application Manifest File。再次粘贴更改。