How to display badges in live tile for windows UAP using NotificationsExtensions.Win10 package?

280 Views Asked by At

I am creating a Windows 10 application. I need to display badges in live tile. I installed NotificationsExtensions.Win10 Nuget package.I use the following code.

  public static void UpdateTileBadgeNumberUsingNotificationExtensions()
    {
        BadgeNumericNotificationContent badgeContent = new BadgeNumericNotificationContent(2);
        BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badgeContent.CreateNotification());
    }

Here CreateNotification method is not available on badgeContent.How can I implement badge count using NotificationsExtensions.Win10 Nuget package.

2

There are 2 best solutions below

2
On BEST ANSWER

Please update your code as follows:

 BadgeNumericNotificationContent badgeContent = new BadgeNumericNotificationContent(2);
 BadgeNotification bnotification = new BadgeNotification(badgeContent.GetXml());
 BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(bnotification);

After you have created a new BadgeNumericNotificationContent instance, you just got a content. You need to call GetXml() from this content and set the xml document to a BadgeNotification instance. Then you can update the badge by the BadgeNotification.

2
On
  var badge = new BadgeNumericNotificationContent(2);
        XmlDocument bdoc = content.GetXml();
        BadgeNotification bnotification = new BadgeNotification(bdoc); 
        BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(bnotification);