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;
try
{
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:
break;
case BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity:
break;
case BackgroundAccessStatus.Denied:
break;
case BackgroundAccessStatus.Unspecified:
break;
default:
break;
}
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();
badgeDOM.LoadXml(badgeXmlString);
BadgeNotification badge = new BadgeNotification(badgeDOM);
BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badge);
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.
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.