WPF – Windows 7 Taskbar Part Two – Jump Lists

About a month ago I started a four part series on how to implement various features of the Windows 7 taskbar which are features that have seemly been forgotten.  This series will attempt to resurrect the Windows 7 taskbar and cover the following:

In this post I will concentrate on using Jump Lists.  A JumpList represents a list of items and tasks displayed as a menu on the Windows 7 taskbar button.  If you don’t know what a Jump List is, just right click an application’s icon that is in the task bar and you will see a menu that may look similar to this:

image

This particular Jump List belongs to Microsoft Outlook.  By using the Jump List I can now easily access commonly used tasks available in Outlook.  Microsoft Word’s Jump List is somewhat different:

image

In Word’s jump list I can easily open recently viewed documents without having to use the File –> Open –> find document somewhere on drive process.  One click and I have exactly what I need.

JumpLists can contain two different types of items; Tasks and Paths.  A JumpTask is simply a shortcut to an application or to functionality of a running application.  A JumpPath is a shortcut to a file or folder as seen above in the Word jump list image.  There are a two ways to go about creating a jump list in WPF.  You can do it in XAML or in code.  We will explore both approaches.

Lets start with the XAML approach first.  We will build on the example we created in the first post on thumbnail buttons.  We are going to add a jump list that will open notepad.  To do this open your App.xaml file in your WPF project and define the following code.

 <JumpList.JumpList>
     <JumpList>
         <JumpTask Title=”Notepad”
                  Description=”JumpTask to open Notepad”
                  ApplicationPath=”%windir%\system32\notepad.exe”
                  IconResourcePath=”%windir%\system32\notepad.exe”
                  IconResourceIndex=”0″/>
     </JumpList>
 </JumpList.JumpList>

You will notice that we simply defined a JumpList and added a JumpTask to it.  We provided a Title which will show as the menu text, the Description will act as the tooltip and the ApplicationPath defines where to find the application we want to open.  We also set the IconResourcePath (where to find the icon) and the IconResourceIndex.  This will show Notepad’s icon in our JumpList menu.  Run the application, right-click the icon in the taskbar and this is what is should look like:

image

Now I know what you are going to ask, “How do I execute tasks in my WPF application that is already running?”.  Well, that one is a bit tricky.  The first thing you need to do is make your WPF application a singleton.  Of course, there is no native support for a single instance application in WPF so you will have to do some workarounds.  Most involve using the WinForm application class.  I recommend hitting up your favorite search engine to find a solution you like.  Once you have a single instance application, you can simply have the JumpTask point to your app and send the neecessary arguments by using the Arguments property on the JumpTask.

Next, lets add a JumpPath to open a video.  Add a JumpPath to the JumpList as follows:

 <JumpList.JumpList>
    <JumpList>

        <JumpPath Path=”C:\Users\Public\Videos\Sample Videos\Wildlife.wmv” />

        <JumpTask Title=”Notepad”
                  Description=”JumpTask to open Notepad”
                  ApplicationPath=”%windir%\system32\notepad.exe”
                  IconResourcePath=”%windir%\system32\notepad.exe”
                  IconResourceIndex=”0″/>
    </JumpList>
</JumpList.JumpList>

Run the application, right-click the application icon and……  Uh…… Where the heck is my JumpPath?  Well, adding a path requires the application to be registered for handling the file extension of the pathname, otherwise the item will not be added to the jump list.  To do this simple follow these steps:

  1. Right-click the file
  2. Choose Open With –> Choose Default Program
  3. Click Browser and find your application
  4. optionally uncheck “Always use selected program…….”
  5. Click OK

Now your application is registered.  Now run your application again and now you should see your JumpPath.  Be sure to run your application by either pressing CTRL+F5 in Visual Studio or by running the exe directly.

image

Now our JumpPath is available and when you click it out application will open it up.

When you define your JupmList in XAML, you are setting a predefined set of commonly used tasks and paths.  This may not be what you want for your jump list so you may be better off creating the jump list in code.  You can accomplish the same thing with the following code:

private void CreateJumpList()
{
    JumpList jumpList = new JumpList();
    JumpList.SetJumpList(Application.Current, jumpList);

    JumpPath jumpPath = new JumpPath();
    jumpPath.Path = @”C:\Users\Public\Videos\Sample Videos\Wildlife.wmv”;
    jumpList.JumpItems.Add(jumpPath);

    JumpTask jumpTask = new JumpTask();
    jumpTask.Title = “Notepad”;
    jumpTask.Description = “JumpTask to open Notepad”;
    jumpTask.ApplicationPath = @”%windir%\system32\notepad.exe”;
    jumpTask.IconResourcePath = @”%windir%\system32\notepad.exe”;
    jumpTask.IconResourceIndex = 0;
    jumpList.JumpItems.Add(jumpTask);

    jumpList.Apply();
}

This will give you more control over adding items to your jump list. 

I know this was a short post, but hopefully it gave you enough information to get started with jump lists.  Download the source and see what you can do.

3 thoughts on “WPF – Windows 7 Taskbar Part Two – Jump Lists”

  1. Seriously?!? Another post about creating a JumpList with notepad.exe??

    Seriously, there are about 10 of the exact same posts like this by searching google for WPF 4 JumpLists.

    How about a useful how to and show us a good example of calling custom event handlers or methods inside our application like in the first couple of screen shots in this post. Like, open a new message or WPF window by sending the JumpList as a parameter to it and do something? Maybe open another part of the application from a list of recent items that you opened before.

  2. @John
    I am sorry this blog post did not instruct you on the more advanced implementations of the JumpList. Keep in mind that advanced implementations of the JumpList is not the problem space this post is trying to address. This is an introductory post and is not meant for someone like you who is looking for a more advanced use of the JumpList. The target audience for this post are people who are not familiar with the JumpList.

    I will consider writing a post covering more advanced implementations after this series is completed.

Comments are closed.