开发者

WPF JumpTask another icon than the default one?

I am using a WPF JumpTask object, and I would like my Windows 7 jumplist icon to be an icon from my own application - but not the default one. A different one.

So how do I do this? I gu开发者_运维百科ess I specify a different icon resource index.

But how do I even store my icons as resources, and how do I know which icon is which index?


According to MSDN

An icon used with a JumpTask must be available as a native resource.

you can only load icons from separate resource file. So, you need to set IconResourcePath property to DLL with your icons. If you have few icons, use IconResourceIndex property to specify needed one.

For example, next code

<Application x:Class="YourApp.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="MainWindow.xaml">
    <JumpList.JumpList>
        <JumpList>
            <JumpTask Title="TargetApp"
                      Description="JumpTask to start TargetApp"
                      ApplicationPath="TargetApp.exe"
                      IconResourcePath="LibWithIcons.dll"
                      IconResourceIndex="2" />
        </JumpList>
    </JumpList.JumpList>
</Application>

will create JumpList and set to JumpTask item TargetApp third icon (null-based numeration) from LibWithIcons.dll. By the way, if JumpTask starts another application usually IconResourcePath is set to the executable file of that application, so it icon will be displayed:

<JumpTask Title="TargetApp"
    Description="JumpTask to start TargetApp"
    ApplicationPath="TargetApp.exe"
    IconResourcePath="TargetApp.exe"
    IconResourceIndex="0" />

How to create icons DLL described on MSDN forums.


It's looking for your icons in a Win32 resource, which is quite different to a managed resource. Take a look at this excellent write-up to understand these - it is possible to create them and specify icon order.

Embed Icons into WPF Application as Resource

I ended up using a great tool created by Einar Eigilson which allows you to add the icons as a resource in a post-build event.

It's also worth noting that I could't get the icons to display when running in Debug mode, regardless of what I did. Even embedding a static win32 resource didn't show any of the icons beyond the main icon. Try testing in Release before you pull your hair out like I did.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜