Customizing Windows 7 Taskbar from WPF – Part 1 (Jumplist Custom Icon)

November 19, 2010

no comments

Windows 7 Taskbar Jumplist takes you right to your favorite applications or frequent files related to your application running in the task bar.


To open a Jump List, just right-click a program icon on the Windows 7 taskbar and the Jumplist pops up.


image


If you look in MSDN for the WPF 4 JumpList class you’ll see a very nice code snippet which creates Jumplist tasks but uses an external DLL as the source of the tasks icons.


First you should know that the WPF 4 JumpList is only a managed wrapper around the Windows 7 Jumplist Native APIs, and the only option to display an icon is to have an icon as native resource.


By default, working with WPF or .NET application you don’t really have a native resource, only a managed one.


Surprisingly a .NET application can have a native resource. Lets see how to create one with icon, combine it with our .NET/WPF application and then use it as our Jumplist Task source.


To add a native resource



  1. In VS2010 open the File menu –> New –> File.

  2. Select the “Native Resource Template” and click Open.

  3. In the opened tab, right click on the ResTemplX.rct folder icon and select ‘”Add Resource…”.

  4. In the opened dialog pick “Icon” and select “New” to create new one or “Import…” to import existing one.

  5. Save the resource file (CTRL+S), as “32-bit Resource file” type (open the combo-box at the bottom) in your project folder.

  6. Open your project properties page, in the “Application” section click on the “Resource file” radio-button and pick the file you’ve just saved.

  7. Build your project.

You’ve just set your project to work with a native resource file (Side effect: your application icon will be picked from there).


Next you should pick the desired icon in your Jumplist task.



  1. To create a Jumplist, open the App.xaml and add the following (not as resource):
    <JumpList.JumpList>
        <JumpList ShowRecentCategory=“True”
                   ShowFrequentCategory=“True”>
            <JumpTask Title=“Notepad”
     
                      
    Description=“Open Notepad.”
     
                      
    ApplicationPath=“C:\Windows\notepad.exe”
                       IconResourcePath=“place-application-exe-fullpath-here” />

        </JumpList
    >
    </
    JumpList.JumpList
    >

  2. Run the application, open its Jumplist and you should see your icon.

image


Note: you can also set the JumpTask.IconResourceIndex (which is zero by default) to a different value for picking a different icon index located in the same resource file.


Now the question is why would you like to have a different icon in first place?


And the answer for that is you want to launch a real command, intercepted by your running application from the Jumpllist. exactly like Windows Media Player and other programs do.


image


In the next post I’ll show how to do that, so stay tuned.


Meanwhile you can download my code from here.

Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*