Wednesday, June 10, 2009 8:32 PM
rudi
Launching views using Jump Lists
Windows 7 has so many cool new features… One of the features that has great potential is the Jump Lists! This article shows how to launch different views for the same application using the Jump List feature of Windows 7
The basics
We will be using the default WPF MVVM application created using the MVVM Toolkit. There is only 2 changes I made before we can start:
- I added a new View/ViewMode called CoolView/CoolViewModel (This is exactly the same code as the MainView/MainViewModel generated). To differentiate the two views, I changed their titles and background colors!
- We also need to change the Application.OnStartup code that was generated to launch different views based on the args passed into the application. If the application is started with InCoolMode as a argument, then the CoolView/CoolViewModel gets loaded else we load MainView/MainViewModel. Here is the code
private void OnStartup(object sender, StartupEventArgs e)
{
if (e.Args.Contains("InCoolMode"))
{
Views.CoolView view = new Views.CoolView();
view.DataContext = new ViewModels.CoolViewModel();
view.Show();
}
else
{
Views.MainView view = new Views.MainView();
view.DataContext = new ViewModels.MainViewModel();
view.Show();
}
}
Now for the “good” stuff
It's a handy way to quickly reach the files you've been working with. To see the files you've used recently, just right click on the icon on your taskbar. So right-clicking on the Word icon will show your most recent Word documents. Plus, if there are other files you want to keep handy, you can just pin them to the Jump List so they’ll always appear. That way, the documents you’re likely to want are just a couple clicks away.
Some programs, such as Windows Media Player, can pre-populate their Jump Lists with common tasks. For example, on the Jump List for Windows Media Player, you’ll see options to Play All Music or resume your last playlist. On the Jump List for Internet Explorer, you’ll see frequently and recently viewed websites. With some programs, you’ll even have quick access to tasks that, in the past, were only available from within the program, such as composing a new e-mail message.
Windows 7 Jump Lists
We will be populating the Jump List with a task to launch the application in “Cool” mode!
Before we can start, we need to download the Windows® API Code Pack for Microsoft® .NET Framework (v0.85).
The Windows® API Code Pack for Microsoft® .NET Framework provides a source code library that can be used to access new Windows 7 features (and some related Windows Vista features) from managed code. These features are not available to developers today in the .NET Framework.
Reference Microsoft.WindowsAPICodePack.dll and Microsoft.WindowsAPICodePack.Shell.dll
Add the following code in Application.Startup
Taskbar.AppID = "MyCoolApp";
JumpList jumpList = Taskbar.JumpList;
string executablePath = Assembly.GetEntryAssembly().Location;
string executableFolder = Path.GetDirectoryName(executablePath);
// Add our user tasks
jumpList.UserTasks.Add(new JumpListLink
{
Title = "CoOl MoDe",
Path = Path.Combine(executableFolder, "JumpListDemo.exe"),
Arguments = "InCoolMode",
IconReference = new IconReference(Path.Combine(executableFolder, "JumpListDemo.exe"), 0)
});
jumpList.RefreshTaskbarList();
This will add a new Task “CoOl MoDe”. Here is how the Jump List looks

And that’s it! Now our super cool mode can be launched using the Jump List…
If you found this article cool or useful, please 
Filed under: WPF, Windows 7, Jump List