Exemple #1
0
        /// <summary>
        /// Gets the XML content of one of the predefined badge templates
        /// so that you can customize it for a badge update.
        /// </summary>
        /// <param name="type">The type of badge template, either a glyph or a number.</param>
        /// <returns>The object that contains the template XML.</returns>
        public static XmlDocument GetTemplateContent(BadgeTemplateType type)
        {
            // Although UWP has two "template types", both return the same XML.
            var xml = new XmlDocument();

            xml.LoadXml("<badge value=\"\" />");
            return(xml);
        }
        private void CreateBadge(object sender, RoutedEventArgs e)
        {
            const BadgeTemplateType badgeTemplateType = BadgeTemplateType.BadgeGlyph;
            XmlDocument             templateContent   = BadgeUpdateManager.GetTemplateContent(badgeTemplateType);

            (templateContent.GetElementsByTagName("badge").FirstOrDefault() as XmlElement)?.SetAttribute("value", "alarm");

            BadgeUpdater badgeUpdater      = BadgeUpdateManager.CreateBadgeUpdaterForApplication();
            var          badgeNotification = new BadgeNotification(templateContent)
            {
                ExpirationTime = new DateTimeOffset(DateTime.UtcNow + TimeSpan.FromSeconds(10))
            };

            badgeUpdater.Update(badgeNotification);
        }
Exemple #3
0
        private void UpdateBadge()
        {
            int itemCount = viewModel.GroceryList.Count;

            BadgeTemplateType templateType = itemCount > 3
                ? BadgeTemplateType.BadgeGlyph : BadgeTemplateType.BadgeNumber;

            XmlDocument badgeXml = BadgeUpdateManager.GetTemplateContent(templateType);

            ((XmlElement)badgeXml.GetElementsByTagName("badge")[0]).SetAttribute("value",
                                                                                 (itemCount > 3) ? "alert" : itemCount.ToString());

            for (int i = 0; i < 5; i++)
            {
                BadgeUpdateManager.CreateBadgeUpdaterForApplication()
                .Update(new BadgeNotification(badgeXml));
            }
        }