How to pin UWP app to the taskbar

Users who love our app may appreciate a way to pin it to the system taskbar directly from the app UI. Universal Windows Platform has an API just for that and even better – it does work with the upcoming Windows 10X as well!

To get access to the API, we first need to check for its presence. TaskbarManager is available since Windows 10 version 16299, so if we want to support earlier versions as well, we should use ApiInformation to verify first:

if (ApiInformation.IsTypePresent("Windows.UI.Shell.TaskbarManager"))
{
// TaskbarManager is available
//
}

When we know TaskbarManager is available, we can retrieve its instance using the GetDefault() method:

var taskbarManager = TaskbarManager.GetDefault();

view raw
GetDefault.cs
hosted with ❤ by GitHub

Some SKUs of Windows 10 don’t have a taskbar (for example Xbox), so first need to verify that:

if (taskbarManager.IsSupported)
{
// taskbar is supported
//
}

To avoid showing the dialog unnecessarily, we should first check if the application is already pinned:

var isPinned = await taskbarManager.IsCurrentAppPinnedAsync();
if (!isPinned)
{
// oh, app is not pinned yet!
//
}

view raw
IsPinned.cs
hosted with ❤ by GitHub

Almost there, just one final check! The TaskbarManager.IsPinningAllowed allows us to check if app pinning is allowed on the device, as organization can block it for work accounts using group policy (however weird a reason for that might be 🤗):

if (taskbarManager.IsPinningAllowed)
{
// we are ready to pin!
//
}

view raw
IsPinningAllowed.cs
hosted with ❤ by GitHub

Now we can finally safely request to pin our app to the taskbar! We can call the asynchronous RequestPinCurrentAppAsync method which returns a bool value indicating if the user accepted the request and pinned the app:

var pinned = await taskbarManager.RequestPinCurrentAppAsync();

view raw
RequestPin.cs
hosted with ❤ by GitHub

The cool thing about this all is that it works on Windows 10X, too!

Application pinned on Windows 10X
Application pinned on Windows 10X

Source code

The example source code and sample app for this article is available here on my GitHub.

Summary

The taskbar was always one of the most important shell components in Windows. With tiles apparently going away in Windows 10X, it is worth adding the ability to pin our app to the taskbar to help users to open it quickly and easily.

Buy me a coffeeBuy me a coffee

2 thoughts on “How to pin UWP app to the taskbar”

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.