Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Badge Notifications in Windows 8

0.00/5 (No votes)
28 Jun 2012 1  
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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here