Tutorials for web designers and developers
Tutorials for Developers_
Close this search box.

What is Badge Notification? | Badge Notification in Windows 8 Store Apps

Hafiz Faraz Mukhtar

Hafiz Faraz Mukhtar

Hafiz Faraz Mukhtar is an expert Web Developer, SEO specialist, and Graphic Designer. Hafiz Faraz is an expert in WordPress design and development. Hire on Upwork | Hire on Fiverr

Badge Notification Picture on the left side shows lock screen of windows 8.1 (Which you can see right now by pressing ‘Windows Key’ + L )

Highlighted area are badge notifications.

Before implementing badge notification things you need to know are: Windows 8.1 can have only 5 badge notification icons. It has to be purely white with transparent background. You need to enable background tasks in manifest (will see in a moment).

Lets do it now!

1. Open visual studio 13 > New project > Visual C# > Blank App

2. In solution explorer, open MainPage.Xaml and add below lines of code between opening and closing tag of Grid. This will add two button.

<StackPanel >
      <Button Click="Button_Click" >Acquire Permission </Button >
      <Button Click="Button_Click_1" >Change Badge </Button >
 </StackPanel >

3. Goto Button_Click event by right clicking and selecting VIEW DEFINITION, then add below code inside curly braces. This will check the status of background task access for app.

 BackgroundAccessStatus status = BackgroundAccessStatus.Unspecified;
                status = await BackgroundExecutionManager.RequestAccessAsync();
            catch (UnauthorizedAccessException)
                // An access denied exception may be thrown if two requests are issued at the same time
                // For this specific sample, that could be if the user double clicks "Request access"

            switch (status)
                case BackgroundAccessStatus.AllowedWithAlwaysOnRealTimeConnectivity:
                case BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity:
                case BackgroundAccessStatus.Denied:
                case BackgroundAccessStatus.Unspecified:

4. Goto Button_Click1 event by right clicking and selecting VIEW DEFINITION, then add below code inside curly braces. This will sets the badge value i.e if you have 15 notifications on facebook it will show 15 below badge icon at lockscreen.

string badgeXmlString = "";
            Windows.Data.Xml.Dom.XmlDocument badgeDOM = new Windows.Data.Xml.Dom.XmlDocument();
            BadgeNotification badge = new BadgeNotification(badgeDOM);

5. Goto Manifest file then add declaration of background task, then check push notification and lastly name of your page where your badge code is.
Configuring Badge Notification
6. Goto manifest file > Application > scroll to NOTIFICATIONS> Select Login Screen Notification as BADGE.
7. Finally goto Manifest file then add visual assets, then add badge logo(needs to be white ONLY and transparent background).

Download Complete code by Mr. Usman-Ur-Rehman

Having any problem implementing above code? Click on this post title and comment below there.

Leave a Reply

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