Managing WPF Screens with Windows 7 Jumplists and the Visual State Manager

We’re having our Singapore launch of Windows 7 this November and in honor of that, I’ll be devoting my upcoming (and long overdue) TechFridays to everything Windows 7. For this post, I’ll be talking about how you can use the Visual State Manager for WPF to manage the different screen states in your application in conjunction with your Windows 7 Jumplists.

Before we start, make sure you have the following downloaded:

1. WPF Toolkit – This enables VSM support in current WPF projects

2. http://code.msdn.microsoft.com/WindowsAPICodePack – provides managed wrappers that allow you to easily incorporate Windows 7 JumpLists into your application

* make sure you add references to the above binaries and your set to go.

If you’re not familiar with the Visual State Manager, you can read http://windowsclient.net/wpf/wpf35/wpf-35sp1-toolkit-visual-state-manager-overview.aspx for a brief overview.

What I have is an application with several screens grouped into panels. I also have a visual state group “ScreenStates” where i have 3 states, one for each screen.

image

This should make for easier screen management. You can make use of Blend behaviors to activate these states on the click of the corresponding navigation button / link. If you open up the Behaviors tab in the asset library, you’ll find the GoToStateAction that you can click and drag onto the appropriate control that you want to trigger the state activation.

image

In the screen below, I added the behavior to my GalleryButton. On the properties panel, you’ll see that you can set the StateName you want to activate on the trigger, in this case, the GalleryButton’s Click event.

image

Next we we want to enable Windows 7 Jumplists in our application. Windows 7 is all about helping users become more efficient and one of the features that enable this is the jumplist. Below is a screenshot of Outlook’s jumplists. The application basically exposes tasks that would normally take a few clicks to get to so instead of having to spend the time starting the app and clicking the appropriate menus/options, you jump straight into the screen you want.

image

Below is one way you can integrate jumplists into the app we are building. First, you’ll need to define and initialize a few variables we will be needing to manage the jumplist: the Jumplist itself, and the folder where the assembly is executing.

        private JumpList WindowJumpList;
        string executableFolder;

	private void Window_Loaded(object sender, System.Windows.RoutedEventArgs e)
	{
			// TODO: Add event handler implementation here.
            WindowJumpList = JumpList.CreateJumpList();
            executableFolder = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);

            initializeJumplist();
            string[] arguments = Environment.GetCommandLineArgs();
            if (arguments.Length > 1)
            {
                ProcessArguments(arguments[1]);
            }
	}

The following code then initializes the jumplist. Note that the tasks are shell links to the application executable, with the state names of our screens as the arguments. This will make it easier later on to process the arguments and activate the appropriate screen.

image

The last method is the ProcessArguments method. There is a slight kink in the VisualStateManager that won’t allow you to “go to state” as you normally would unless the target is a UserControl. In this case, we had to use a work around which i found here

image

when you compile and run your app, you’ll see the following jumplist tasks and will be able to activate the corresponding screens straight from the jumplist.

image

image

You can download and try out the code here:

http://cid-bdfb7845c22e26b6.skydrive.live.com/embedicon.aspx/Projects/TechFriday/JumplistScreenManagement.zip

This version launches a new instance every time you click on a task on the jumplist. In my next post, I’ll post a sample on how to create jumplist enabled single instance WPF applications. Till next time!

2 thoughts on “Managing WPF Screens with Windows 7 Jumplists and the Visual State Manager”

  1. […] For the Windows 7 uninitiated, jumplists is a new introduction to the Windows family. Making the taskbar more functional, jumplists is a fast and easy way to access common tasks on the application without having it on focus. This makes things much easier and faster to do. So far a bunch of apps already has it and more on the way. (Saw some Firefox jumplists a couple of days back). If you want more nerd rave on jumplists, check out Aimee’s blog on making your own jumplists. […]

    Like

Leave a reply to Making Your Win7 JumpLists Trigger on the Same Application Instance | Aimee Gurl... Cancel reply