Search code examples
c#xamlwindows-10uap

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


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.


Solution

  • 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.