Making Your Win7 JumpLists Trigger on the Same Application Instance

As promised in my previous post, I’ll be talking about how to create jumplist integrated single instance applications, much like how Outlook, Windows Media Player.

At first, i thought it would need to involve a bit of windows messaging but then I found this blog post that details how to create single instance WPF applications. I rewrote our sample from the previous post to adopt this model. I based my code on the post so I recommend reading that post first to have a better understanding of how we are creating this single instance application.

Explaining a bit what is going on here, we basically have 3 major classes:

image

The SingleInstanceManager, as the name implies, manages the instances of your application. If you take a look at the code, basically it creates an instance of your application if it is an initial startup. When a next instance is triggered to start up, it activates the the MainWindow through Win7Application and processes any arguments passed in the triggering of the subsequent instances.

Win7Application is basically our replacement for App.xaml because we want to be able to control when we activate the MainWindow of our application. We also process any arguments of our application in this class.

  public void ProcessArgs(string[] args, bool isFirstInstance)
        {
            if (args.Length > 0)
            {
                if (isFirstInstance)
                    AppWindow.initState = args[0];
                else
                    AppWindow.updateState(args[0]);
            }
            
        }

If you look at the ProcessArgs method in the sample attached, we’re basically setting an initial state (initState) property to the value of the argument as this is expected from the jumplists we have defined in my previous post. If this is not the first instance, we call the updateState() method which I have exposed as a public method in the MainWindow class. 

These are basically the changes I made to MainWindow.xaml.cs:

        private void Window_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {

            WindowJumpList = JumpList.CreateJumpList();
            initializeJumplist();
            if (initState != null)
                updateState(initState);
          
        }
        public  void updateState(string state)
        {
            ExtendedVisualStateManager.GoToElementState(LayoutRoot, state, true);
            
        }

You can download the source here:

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

2 thoughts on “Making Your Win7 JumpLists Trigger on the Same Application Instance”

Leave a reply to Arian Kulp Cancel reply