Skip to content

Instantly share code, notes, and snippets.

Created October 2, 2018 15:06
What would you like to do?
Update the badge of the tile from a WPF packaged app
using BooksLib.Services;
using System;
using System.Threading;
using System.Windows;
using Windows.Data.Xml.Dom;
using Windows.UI.Notifications;
namespace DesktopBridgeSample.Services
public class UpdateTileService : IUpdateTileService
private static int s_badgeNumber = 0;
public static int GetBadgeNumber() =>
Interlocked.Increment(ref s_badgeNumber);
public void UpdateTile()
XmlDocument badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);
XmlNodeList badge = badgeXml.GetElementsByTagName("badge");
badge[0].Attributes[0].NodeValue = GetBadgeNumber().ToString();
var notification = new BadgeNotification(badgeXml);
catch (Exception ex) when (ex.HResult == -2147023728)
MessageBox.Show("not started with a package?");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment