Universal Windows Platform – Badges

Step 1

If not already, follow Setup and Start on how to Install and get Started with Visual Studio 2017 or in Windows 10 choose Start, and then from the Start Menu locate and select Visual Studio 2017.


Step 2

Once Visual Studio Community 2017 has started, from the Menu choose File, then New then Project…


Step 3

From New Project choose Visual C# from Installed, Templates then choose Blank App (Universal Windows) and then type in a Name and select a Location and then select Ok to create the Project


Step 4

Then in New Universal Windows Project you need to select the Target Version to be Windows 10 Creators Update (10.0; Build 15063) and the Minimum Version to be at least Windows 10 Anniversary Update (10.0; Build 14393) or Windows 10 Creators Update (10.0; Build 15063)


Step 5

From the Menu choose Project, then Add New Item…


Step 6

From the Add New Item choose Visual C# from Installed then choose Code then select Code File and then in the Name as Library.cs and then select Add to add the file to the Project


Step 7

Then in the Code View for Library.cs the following should be entered:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Core;
using Windows.Data.Xml.Dom;
using Windows.UI.Notifications;
using Windows.UI.StartScreen;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

public class Library
    private List<string> glyphs = new List<string>
        "number", "activity", "alarm", "attention", "available", "away",
        "busy", "error", "newMessage", "paused", "playing", "unavailable"

    private async Task<string> Dialog()
        ComboBox glyph = new ComboBox()
            HorizontalAlignment = HorizontalAlignment.Stretch,
            Margin = new Thickness(5),
            ItemsSource = glyphs
        glyph.SelectedIndex = 0;
        TextBox number = new TextBox()
            PlaceholderText = "Number",
            Margin = new Thickness(5)
        StackPanel panel = new StackPanel()
            Orientation = Orientation.Vertical
        ContentDialog dialog = new ContentDialog()
            Title = "Badges",
            PrimaryButtonText = "Update",
            CloseButtonText = "Cancel",
            Content = panel
        ContentDialogResult result = await dialog.ShowAsync();
        if (result == ContentDialogResult.Primary)
            string selected = (string)glyph.SelectedItem;
            return (selected == "number") ? number.Text : selected;
        return null;

    private void UpdateBadge(string value)
        bool isNumber = int.TryParse(value, out int number);
        XmlDocument badge = BadgeUpdateManager.GetTemplateContent(isNumber ?
            BadgeTemplateType.BadgeNumber : BadgeTemplateType.BadgeGlyph);
        XmlNodeList attributes = badge.GetElementsByTagName("badge");
        IXmlNode node = attributes[0].Attributes.GetNamedItem("value");
        node.NodeValue = value;
        BadgeNotification notification = new BadgeNotification(badge);

    public async Task<bool> PinAsync()
        bool isPinned = false;
        AppListEntry entry = (await Package.Current.GetAppListEntriesAsync()).FirstOrDefault();
        if (entry != null)
            isPinned = await StartScreenManager.GetDefault().ContainsAppListEntryAsync(entry);
        if (!isPinned)
            isPinned = await StartScreenManager.GetDefault().RequestAddAppListEntryAsync(entry);
        return isPinned;

    public async void Badge()
        string result = await Dialog();
        if(result != null)

Step 8

Then in the Solution Explorer select MainPage.xaml


Step 9

From the Menu choose View and then Designer


Step 10

The Design View will be displayed along with the XAML View and in this between the Grid and /Grid elements, enter the following XAML:

<CommandBar VerticalAlignment="Bottom">
	<AppBarButton Name="Pin" Icon="Pin" Label="Pin" Click="Pin_Click"/>
	<AppBarButton Name="Badge" Icon="SetTile" Label="Badge" Click="Badge_Click"/>

It should appear as such:


Step 11

From the Menu choose View and then Code


Step 12

Once in the Code View, below the public MainPage() { … } the following Code should be entered:

Library library = new Library();

private async void Pin_Click(object sender, RoutedEventArgs e)
	await library.PinAsync();

private void Badge_Click(object sender, RoutedEventArgs e)

It should then appear as such:


Step 13

That completes the Universal Windows Application so Save the Project then in Visual Studio select the Local Machine to run the Application


Step 14

Once started the Application should then appear


Step 15

After the Application has started running you can then select Pin to pin-to-start the Application and then select Badge display a Dialog where you select Number or Glyph from the ComboBox and Number to use if that option has been selected from the ComboBox. The Badge will be displayed in Windows 10 on the TaskBar or the Tile for the Application.


Step 16

To Exit the application select Stop in Visual Studio


Creative Commons License

One thought on “Universal Windows Platform – Badges

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s