Click here to Skip to main content
Click here to Skip to main content

Badge Notifications in Windows 8

, 28 Jun 2012
Rate this:
Please Sign up or sign in to vote.
It shows how to display a badge notification in Windows 8 metro app

Introduction

Badge is a type of Push Notification available in Windows 8. It is displayed over the top of a tile. Badges are small icons that are shown in the lower right corner of a tile. The tile can either be a default tile or a tile with a notification.

A badge can display either a number from 1-99 or a status glyph. Now it is to be noticed that 99 is the largest number to be displayed as a badge. Even if you provide a number larger than 99, it will show badge notification as 99 only.You can have a full overview about number badges and glyph badges from here.

Using the code

Displaying a badge is similar to displaying a notification. So at first the following namespaces should be included:

Using Windows.UI.Notifications;
Using Windows.Data.Xml.Dom;

The following code is used for displaying a badge in Windows 8 metro App :

XmlDocument xmldoc = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);
XmlElement textnode = (XmlElement)xmldoc.SelectSingleNode("/badge");
textnode.SetAttribute("value", "available");
BadgeNotification not = new BadgeNotification(xmldoc);
BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(not);  

Now we will learn what the following statements will do.The first line gets the blank XML badge template for a numeric badge. For a glyph badge, the code will be:

XmlDocument xmldoc = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeGylph);

The schema for both types of badges are same i.e. <badge value=””/>

The next two lines set the value attribute in the schema. For the number badge this will be one or two digits. For the glyph badge it will be one of the following values: none, activity, alert, available, away, busy, newMessage, paused, playing, unavailable, error.

The last two lines packages the XML into a notification and creates a badge object and display it on the tile.

Points of Interest

The Badge Notification will look like this in the tile:

The first image shows numeric badge while the second one shows gylph badge

We can also remove the badge notification with the help of following code:

BadgeUpdateManager.CreateBadgeUpdaterForApplication().Clear(); 

Now you all must be thinking that what is the usefulness of this badge or where this badge needs to be used?????

A Badge can be used –

  • To show no. of unread mails in a mail application
  • To show no. of online members in a chat
  • To display the chat status
  • To display the current level of game being played

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

ROHIT SHAW

India India
No Biography provided
Follow on   Twitter

Comments and Discussions

 
GeneralMy vote of 5 PinmemberVistaaR7-Aug-12 21:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140814.1 | Last Updated 28 Jun 2012
Article Copyright 2012 by ROHIT SHAW
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid