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:
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:
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.
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:
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:
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:
- Right-click the file
- Choose Open With –> Choose Default Program
- Click Browser and find your application
- optionally uncheck “Always use selected program…….”
- 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.
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:
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.