Windows 10 Jumplist

Jump lists have been a part of classic Windows apps for years giving you the ability to jump back into areas of those apps where you left off or perform quick tasks, for example, opening a recent file or starting a new email.

With the current preview SDK for universal Windows apps, you can get this same functionality in UWP apps from both the taskbar and Start menu when right clicking on tiles.

As mentioned above, this feature is currently only available in the latest preview SDK and requires you to be running a Windows Insider build greater than 10565 but these new features should be available with the Threshold 2 update coming later this month. You can download the latest Windows Insider build through updates on your PC and you’ll want to download and install the Windows 10 SDK Preview Build 10563.

Implementing the jump list in your UWP app

Implementing the jump list in your UWP app couldn’t be easier. Below, I’ll show you how to setup the items in your app jump list and then how you manage the arguments that are passed through to your application when the user selects an item from the list.


private static async Task SetupJumpList()
{
    JumpList jumpList = await JumpList.LoadCurrentAsync();
    jumpList.Items.Clear();

    JumpListItem photoItem = JumpListItem.CreateWithArguments("photo", "Capture photo");
    photoItem.Logo = new Uri("ms-appx:///Assets/photo.png");
    JumpListItem videoItem = JumpListItem.CreateWithArguments("video", "Capture video");
    videoItem.Logo = new Uri("ms-appx:///Assets/video.png");

    jumpList.Items.Add(photoItem);
    jumpList.Items.Add(videoItem);
 
    await jumpList.SaveAsync();
}

The code above shows you how to set up the jump list. You’ll only have to run this once, but if you ever update it, you’ll want to make sure it runs again for your app to clear down the items and re-establish them.

Now, to handle those items being selected from the menu, you’ll want to add the functionality into the OnLaunched method in the App.xaml.cs file. The argument that you added to the jumplist, e.g. “photo”, will be passed through in the LaunchActivatedEventArgs as the Argument property.

You’ll need to handle two scenarios here as you could end up causing problems with your apps. These scenarios are when the app is running and when it isn’t. You’ll do this as follows:


protected override async void OnLaunched(LaunchActivatedEventArgs e)
{
    Frame rootFrame = Window.Current.Content as Frame;

    // Do not repeat app initialization when the Window already has content,
    // just ensure that the window is active
    if (rootFrame == null)
    {
        // Create a Frame to act as the navigation context and navigate to the first page
        rootFrame = new Frame();

        rootFrame.NavigationFailed += OnNavigationFailed;

        if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
        {
            //TODO: Load state from previously suspended application
        }

        // Place the frame in the current Window
        Window.Current.Content = rootFrame;
    }

    await SetupJumpList();

    if (rootFrame.Content == null)
    {
        // When the navigation stack isn't restored navigate to the first page,
        // configuring the new page by passing required information as a navigation
        // parameter
        rootFrame.Navigate(typeof(MainPage), e.Arguments);
    }
    else
    {
        var page = rootFrame.Content as MainPage;
        page?.OnLaunchedEvent(e.Arguments);
    }

    // Ensure the current window is active
    Window.Current.Activate();
}

You then need to handle what you do with that argument in your app. In the example above, I’m passing the arguments straight to the page but you can pass it to a handler which is designed to handle launch events.

If you want to see more on how this works, you can download my DDD North sample from GitHub which contains a project called Sandbox. That project shows you how the jump list works.

As a note to end on, if you’re wanting to try out this preview SDK, remember that you can’t publish these apps to the Windows Store so retarget your apps to the current release of the SDK, 10.0.10240.0.

Author James Croft

James is a senior software developer for Black Marble and Microsoft MVP in Windows Development with over 6 years of experience developing applications for the Windows platform. James’s passion for learning new technologies gives him the opportunities to expose them to the wider community through tutorials, lessons learned and best practices through his online blog site, personal YouTube channel, and local communities through talks at events, schools and universities.

More posts by James Croft

Leave a comment