简体   繁体   English

WPF JumpList 图标未填充

[英]WPF JumpList Icon not populating

I have set up a JumpList in my WPF Application.我在我的 WPF 应用程序中设置了一个 JumpList。

The JumpList is fully functional apart from the Icons are not displaying, this is what I am seeing in my Taskbar:除了不显示图标外,JumpList 功能齐全,这是我在任务栏中看到的:

在此处输入图像描述

Here is the code I have to create the JumpTask:这是我必须创建 JumpTask 的代码:

using System.Windows.Shell;

public JumpTask BuildJumpTask
{
    get
    {
        return new JumpTask
        {
            Arguments = Argument,
            ApplicationPath = Assembly.GetEntryAssembly()?.Location,
            Description = GenerateDescription(),
            IconResourcePath = GetIconPath(),
            Title = Name
        };
    }
}

Private string GetIconPath()
{
    return Type switch
    {
        JumpListItemType.About => Path.GetFullPath(@"Assets\Icons\JumpList\About.ico"),
        JumpListItemType.Help => Path.GetFullPath(@"Assets\Icons\JumpList\Help.ico"),
        JumpListItemType.Quit => Path.GetFullPath(@"Assets\Icons\JumpList\Quit.ico"),
        JumpListItemType.Settings => Path.GetFullPath(@"Assets\Icons\JumpList\Settings.ico"),
        JumpListItemType.Sign_Out => Path.GetFullPath(@"Assets\Icons\JumpList\Sign_Out.ico"),
            _ => null!
    };
}

All.ico files are being output to the expected directory, All.ico 文件正在 output 到预期目录,

I am using the following Properties for them files:我正在为它们的文件使用以下属性:

Build Action: Embedded resource (I have also tried Content)构建操作:嵌入式资源(我也尝试过内容)

Copy to Output Directory: Copy if newer复制到 Output 目录:如果较新则复制

The documentation for JumpTask.IconResourcePath states (emphasis mine): JumpTask.IconResourcePath的文档指出(强调我的):

https://learn.microsoft.com/en-us/do.net/api/system.windows.shell.jumptask.iconresourcepath https://learn.microsoft.com/en-us/do.net/api/system.windows.shell.jumptask.iconresourcepath

The path to a resource that contains the icon.包含图标的资源的路径。 The default is null .默认值为null
[...] An icon used with a JumpTask must be available as a native resource . [...] 与JumpTask一起使用的图标必须作为本地资源提供

Therefore you cannot specify the path to a PNG file for the JumpList icon - this makes sense because Win32 Icons support multiple sizes (eg high DPI, large icons, etc) instead of single images - you can't do that with a PNG file.因此,您不能为 JumpList 图标指定 PNG 文件的路径——这是有道理的,因为 Win32 图标支持多种尺寸(例如高 DPI、大图标等)而不是单个图像——您不能使用 PNG 文件来做到这一点。

Fortunately you don't need to fire-up VisualC++ just to build a .dll file containing a handful of icons: this QA has instructions for how to add multiple .ico files as native ICON / ICONDIRECTORY resources: Adding multiple Icons (Win32-Resource) to .NET-Application - Note that the C# compiler -win32icon option only lets you specify a single icon (as the application icon of the .exe file), making it useless for this purpose.幸运的是,您不需要启动 VisualC++ 来构建一个包含少量图标的.dll文件:此 QA 有关于如何将多个.ico文件添加为本机ICON / ICONDIRECTORY资源的说明: 添加多个图标(Win32-Resource ) 到 .NET-Application - 请注意,C# 编译器-win32icon选项仅允许您指定单个图标(作为.exe文件的应用程序图标),使其无法用于此目的。

Don't forget to ensure you include suitable icon artwork at 16x16, 24x24, and 32x32 to ensure your jump-list items look acceptable on non-96dpi displays.不要忘记确保包含 16x16、24x24 和 32x32 的合适图标插图,以确保您的跳转列表项目在非 96dpi 显示器上看起来可以接受。

Also note that Win32 native resources are an entirely distinct concept from .NET .resources / .resx - and also separate from WPF/XAML <ResourceDictionary> objects too.另请注意,Win32本机资源是与 .NET .resources / .resx完全不同的概念 - 并且也与 WPF/XAML <ResourceDictionary>对象分开。

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

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