Inheritance: IBadgeNotification
        public static void UpdateTile(int value)
        {
            var type = BadgeTemplateType.BadgeNumber;
            var xml = BadgeUpdateManager.GetTemplateContent(type);
            var elements = xml.GetElementsByTagName("badge");
            var element = elements[0] as XmlElement;
            element.SetAttribute("value", value.ToString());

            var updater = BadgeUpdateManager.CreateBadgeUpdaterForApplication();
            var notification = new BadgeNotification(xml);
            updater.Update(notification);

            Debug.WriteLine("Background task badge updated: " + value.ToString());

            var template = ToastTemplateType.ToastText01;
            xml = ToastNotificationManager.GetTemplateContent(template);
            var text = xml.CreateTextNode(string.Format("Badge updated to {0}", value));
            elements = xml.GetElementsByTagName("text");
            elements[0].AppendChild(text);

            var toast = new ToastNotification(xml);
            var notifier = ToastNotificationManager.CreateToastNotifier();
            notifier.Show(toast);

            Debug.WriteLine("Background task toast shown: " + value.ToString());
        }
Exemple #2
0
       public static void Update(string item1)
       {
           XmlDocument doctoast = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);
           var txtnodes = doctoast.GetElementsByTagName("text");
    
            ((XmlElement)txtnodes[0]).InnerText =item1;
              
           
           // 发送Toast通知
           ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(doctoast));


           XmlDocument badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);
           XmlElement badgeElement = (XmlElement)badgeXml.SelectSingleNode("/badge");
           badgeElement.SetAttribute("value", "88");
           BadgeNotification badge = new BadgeNotification(badgeXml);
           BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badge);



           //// 更新磁贴
           //Windows.Data.Xml.Dom.XmlDocument doc = Windows.UI.Notifications.TileUpdateManager.GetTemplateContent(Windows.UI.Notifications.TileTemplateType.TileSquare150x150Text02);
           //var nodes = doc.SelectNodes("tile/visual/binding/text");
           //if (nodes.Count >= 2)
           //{
           //    // 修改XML值
           //    ((XmlElement)nodes[0]).InnerText = items[0];
           //    ((XmlElement)nodes[1]).InnerText = items[1];
           //}
           //// 更新磁贴
           //TileUpdateManager.CreateTileUpdaterForApplication().Update(new TileNotification(doc));

           // 顺便也发一下Toast通知
       }
        private async void ButtonUpdateBadgeNumber_Click(object sender, RoutedEventArgs e)
        {
            int num;

            if (!int.TryParse(TextBoxNumber.Text, out num))
            {
                await new MessageDialog("You must provide a valid integer.", "Error").ShowAsync();
                return;
            }

            // Get the blank badge XML payload for a badge number
            XmlDocument badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);

            // Set the value of the badge in the XML to our number
            XmlElement badgeElement = badgeXml.SelectSingleNode("/badge") as XmlElement;
            badgeElement.SetAttribute("value", num.ToString());

            // Create the badge notification
            BadgeNotification badge = new BadgeNotification(badgeXml);

            // Create the badge updater for the application
            BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForApplication();

            // And update the badge
            badgeUpdater.Update(badge);
        }
 public void SetBadgeGlyph(GlyphValue glyph)
 {
     BadgeGlyphNotificationContent badgeContent = new BadgeGlyphNotificationContent(glyph);
     BadgeNotification badgeNotification = new BadgeNotification(badgeContent.GetXml());
     badgeNotification.ExpirationTime = DateTimeOffset.UtcNow.AddHours(1);
     BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badgeNotification);
 }
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            var deferal = taskInstance.GetDeferral();
            if (taskInstance.TriggerDetails is RawNotification)
            {
                var details = taskInstance.TriggerDetails as RawNotification;
                var arguments = details.Content.Split(':');

                if (arguments.Count() > 0)
                {

                    switch (arguments[0])
                    {
                        case "new_items":
                            if (arguments.Count() > 1)
                            {
                                XmlDocument badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);
                                XmlElement badgeElement = (XmlElement)badgeXml.SelectSingleNode("/badge");
                                badgeElement.SetAttribute("value", arguments[1]);
                                BadgeNotification badge = new BadgeNotification(badgeXml);
                                BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badge);
                            }
                            break;
                    }
                }
            }


            

            


            deferal.Complete();
        }
Exemple #6
0
        public void Update(BadgeNotification notification)
        {
            var element        = notification.Content.SelectSingleNode("/badge") as XmlElement;
            var attributeValue = element?.GetAttribute("value");

            NSApplication.SharedApplication.DockTile.BadgeLabel = attributeValue ?? "";
        }
Exemple #7
0
 public static void UpdateBadgeCounter(int count)
 {
     var template = "<badge value=\"" + count + "\" />";
     var templateXml = new XmlDocument ();
     templateXml.LoadXml (template);
     var badge = new BadgeNotification (templateXml);
     BadgeUpdateManager.CreateBadgeUpdaterForApplication ().Update (badge);
 }
 public void SetBadgeCount(int count)
 {
     var template = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);
     var badgeNode = template.GetElementsByTagName("badge");
     badgeNode[0].Attributes[0].NodeValue = count.ToString();
     var notification = new BadgeNotification(template);
     BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(notification);
 }
 public static void SetBadgeCountOnTile(int count)
 {
     //Update the badge on the real tile 
     XmlDocument badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);
     XmlElement badgeElement = (XmlElement)badgeXml.SelectSingleNode("/badge");
     badgeElement.SetAttribute("value", count.ToString());
     BadgeNotification badge = new BadgeNotification(badgeXml);
     BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badge);
 }
      /// <summary>
      /// Sets the badge.
      /// </summary>
      /// <param name="badgeNumber">The badge number.</param>
      /// <param name="title">The title. Used only by Android</param>
      public void SetBadge(int badgeNumber, string title = null)
      {
          var badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);
          var badgeElement = (XmlElement)badgeXml.SelectSingleNode("/badge");
          badgeElement.SetAttribute("value", badgeNumber.ToString());

          var badge = new BadgeNotification(badgeXml);
          BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badge);
      }
        void UpdateBadge()
        {
            XmlDocument badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeGlyph);
            XmlElement badgeElement = (XmlElement)badgeXml.SelectSingleNode("/badge");
            badgeElement.SetAttribute("value", "error");

            var badgeNotification = new BadgeNotification(badgeXml);
            BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badgeNotification);
        }
        public static void ShowBadgeNotification(int number)
        {
            var badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeGlyph);
            var badgeElement = (XmlElement)badgeXml.SelectSingleNode("/badge");
            badgeElement.SetAttribute("value", number.ToString());

            var badge = new BadgeNotification(badgeXml);
            badgeUpdater.Update(badge);
        }
 private void SendBadgeWithStringManipulation_Click(object sender, RoutedEventArgs e)
 {
     string badgeXmlString = "<badge value='6'/>";
     Windows.Data.Xml.Dom.XmlDocument badgeDOM = new Windows.Data.Xml.Dom.XmlDocument();
     badgeDOM.LoadXml(badgeXmlString);
     BadgeNotification badge = new BadgeNotification(badgeDOM);
     BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badge);
     rootPage.NotifyUser("Badge notification sent", NotifyType.StatusMessage);
 }
Exemple #14
0
        public static void ShowNotificationBadge(int value)
        {
            var badgeXml     = Notifications.BadgeUpdateManager.GetTemplateContent(Notifications.BadgeTemplateType.BadgeNumber);
            var badgeElement = (XmlElement)badgeXml.SelectSingleNode("/badge");

            badgeElement.SetAttribute("value", value.ToString());
            var notification = new Notifications.BadgeNotification(badgeXml);

            Notifications.BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(notification);
        }
        public static void UpdateBadgeCounter(int number)
        {
            var badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);

            XmlElement badgeElement = (XmlElement)badgeXml.SelectSingleNode("/badge");
            badgeElement.SetAttribute("value", number.ToString());

            BadgeNotification badgeNotification = new BadgeNotification(badgeXml);
            BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badgeNotification);
        }
Exemple #16
0
        public static void UpdateBadge(int wordCount)
             
        {
            XmlDocument xdoc = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);
            XmlElement xBadge = (XmlElement)xdoc.SelectSingleNode("/badge");
            xBadge.SetAttribute("value", wordCount.ToString());
            BadgeNotification notifi = new BadgeNotification(xdoc);
            BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(notifi);

        }
        private void SendBadgeNotification_Click(object sender, RoutedEventArgs e)
        {
            string xmlContent = "<badge version='1' value='64'/>";

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(xmlContent);

            BadgeNotification notification = new BadgeNotification(xmlDoc);

            BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(notification);
        }
        public void SetBadgeNumber(int number)
        {
            XmlDocument badgeData = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);
            XmlNodeList badgeXML = badgeData.GetElementsByTagName("badge");


            ((XmlElement)badgeXML[0]).SetAttribute("value", (number).ToString());

            BadgeNotification badge = new BadgeNotification(badgeData);
            BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badge);
        }
Exemple #19
0
        public void Update(BadgeNotification notification)
        {
            if (notification is null)
            {
                throw new ArgumentNullException(nameof(notification));
            }

            var element        = notification.Content.SelectSingleNode(BadgeNodeXPath) as XmlElement;
            var attributeValue = element?.GetAttribute(ValueAttribute);

            SetBadge(attributeValue);
        }
Exemple #20
0
        public void Update(BadgeNotification notification)
        {
            var element        = notification.Content.SelectSingleNode("/badge") as XmlElement;
            var attributeValue = element?.GetAttribute("value");

            if (int.TryParse(attributeValue, out var badgeNumber))
            {
                UIApplication.SharedApplication.ApplicationIconBadgeNumber = badgeNumber;
            }
            else
            {
                Clear();
            }
        }
        private void OnSendStandardToastClicked(object sender, RoutedEventArgs e)
        {
            string xml = @"<toast>
                              <visual>
                                <binding template=""ToastGeneric"">
                                  <image placement=""appLogoOverride"" src=""Assets/MicrosoftLogo.png"" />
                                  <text>Hello insiders!</text>
                                  <image placement=""inline"" src=""Assets/TRexInsider.png"" />
                                  <text>Check out this image. Isn’t it awesome?</text>
                                </binding>
                              </visual>
                            </toast>";

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xml);

            ToastNotification notification = new ToastNotification(doc);
            ToastNotificationManager.CreateToastNotifier().Show(notification);

            int badgeCounter;
            if (ApplicationData.Current.LocalSettings.Values.ContainsKey("ToastCounter"))
            {
                badgeCounter = (int) ApplicationData.Current.LocalSettings.Values["ToastCounter"];
            }
            else
            {
                badgeCounter = 0;
            }

            badgeCounter++;

            // Get the blank badge XML payload for a badge number
            XmlDocument badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);

            // Set the value of the badge in the XML to our number
            XmlElement badgeElement = badgeXml.SelectSingleNode("/badge") as XmlElement;
            badgeElement.SetAttribute("value", badgeCounter.ToString());

            // Create the badge notification
            BadgeNotification badge = new BadgeNotification(badgeXml);

            // Create the badge updater for the application
            BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForApplication();

            // And update the badge
            badgeUpdater.Update(badge);

            ApplicationData.Current.LocalSettings.Values["ToastCounter"] = badgeCounter;
        }
        private void LockScreenButton_Click(object sender, RoutedEventArgs e)
        {
            BackgroundAccessStatus status = BackgroundExecutionManager.GetAccessStatus();
            
            if ((status == BackgroundAccessStatus.AllowedWithAlwaysOnRealTimeConnectivity) ||
                (status == BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity))
            {
                XmlDocument badgeData = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);
                XmlNodeList badgeXML = badgeData.GetElementsByTagName("badge");
                ((XmlElement)badgeXML[0]).SetAttribute("value", "Playing");

                BadgeNotification badge = new BadgeNotification(badgeData);
                BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badge);
            }
        }
Exemple #23
0
 /// <summary>
 /// Shows badge notifications in live tile
 /// </summary>
 /// <param name="value">"alert", "activity", "newMessage", "error" or String.Empty/null to clear</param>
 public static void ShowNotificationBadge(string value)
 {
     if (!string.IsNullOrEmpty(value))
     {
         var badgeXml     = Notifications.BadgeUpdateManager.GetTemplateContent(Notifications.BadgeTemplateType.BadgeGlyph);
         var badgeElement = (XmlElement)badgeXml.SelectSingleNode("/badge");
         badgeElement.SetAttribute("value", value);
         var notification = new Notifications.BadgeNotification(badgeXml);
         Notifications.BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(notification);
     }
     else
     {
         Notifications.BadgeUpdateManager.CreateBadgeUpdaterForApplication().Clear();
     }
 }
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            int counter = 0;
            if (!ApplicationData.Current.LocalSettings.Values.ContainsKey("ToastCounter"))
            {
                counter = 0;
            }
            else
            {
                counter = (int) ApplicationData.Current.LocalSettings.Values["ToastCounter"];
            }

            var details = taskInstance.TriggerDetails as ToastNotificationHistoryChangedTriggerDetail;
            switch (details.ChangeType)
            {
                case ToastHistoryChangedType.Cleared:
                    counter = 0;
                    break;
                case ToastHistoryChangedType.Removed:
                    counter--;
                    break;
                case ToastHistoryChangedType.Expired:
                    counter--;
                    break;
                case ToastHistoryChangedType.Added:
                    counter++;
                    break;
            }

            ApplicationData.Current.LocalSettings.Values["ToastCounter"] = counter;

            // Get the blank badge XML payload for a badge number
            XmlDocument badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);

            // Set the value of the badge in the XML to our number
            XmlElement badgeElement = badgeXml.SelectSingleNode("/badge") as XmlElement;
            badgeElement.SetAttribute("value", counter.ToString());

            // Create the badge notification
            BadgeNotification badge = new BadgeNotification(badgeXml);

            // Create the badge updater for the application
            BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForApplication();

            // And update the badge
            badgeUpdater.Update(badge);
        }
Exemple #25
0
       public static void Note()
        {
            XmlDocument tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150PeekImageAndText01);

            XmlNodeList tileTextAttributes = tileXml.GetElementsByTagName("text");
            tileTextAttributes[0].InnerText = TaskLists(0);
            XmlNodeList tileTextAttributes1 = tileXml.GetElementsByTagName("text");
            tileTextAttributes[1].InnerText = TaskLists(1);
            XmlNodeList tileTextAttributes2 = tileXml.GetElementsByTagName("text");
            tileTextAttributes[2].InnerText = TaskLists(2);

            XmlNodeList tileImageAttributes = tileXml.GetElementsByTagName("image");
            ((XmlElement)tileImageAttributes[0]).SetAttribute("src", "ms-appx:///assets/Square150x150Logo.png");

            XmlDocument squareTileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWide310x150PeekImageCollection02);

            XmlNodeList squareTileTextAttributes = squareTileXml.GetElementsByTagName("text");
            squareTileTextAttributes[0].AppendChild(squareTileXml.CreateTextNode(TaskLists(0)));

            XmlNodeList squareTileTextAttributes3 = squareTileXml.GetElementsByTagName("text");
            squareTileTextAttributes[1].AppendChild(squareTileXml.CreateTextNode(TaskLists(1)));

            XmlNodeList squareTileTextAttributes4 = squareTileXml.GetElementsByTagName("text");
            squareTileTextAttributes[2].AppendChild(squareTileXml.CreateTextNode(TaskLists(2)));

            IXmlNode node = tileXml.ImportNode(squareTileXml.GetElementsByTagName("binding").Item(0), true);
            tileXml.GetElementsByTagName("visual").Item(0).AppendChild(node);

            TileNotification tileNotification = new TileNotification(tileXml);

            tileNotification.ExpirationTime = DateTimeOffset.UtcNow.AddDays(365);

            TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification);

            XmlDocument badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);
            XmlElement badgeElement = (XmlElement)badgeXml.SelectSingleNode("/badge");
            badgeElement.SetAttribute("value", BadgeNum());
            BadgeNotification badge = new BadgeNotification(badgeXml);
            BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badge);
            if (BadgeNum() == "0")
            {
                BadgeUpdateManager.CreateBadgeUpdaterForApplication().Clear();
            }
        }
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            var toasts = ToastNotificationManager.History.GetHistory();
            if (toasts != null)
            {
                var count = toasts.Count();

                XmlDocument badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);
                XmlElement badgeElement = (XmlElement)badgeXml.SelectSingleNode("/badge");
                badgeElement.SetAttribute("value", count.ToString());

                BadgeNotification badge = new BadgeNotification(badgeXml);
                BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badge);

                // Update the app data
                UpdateAppData(toasts);

                taskInstance.Progress = 100;
            }
        }
        private void ButtonUpdateBadgeGlyph_Click(object sender, RoutedEventArgs e)
        {
            string badgeGlyphValue = ComboBoxBadgeGlyph.SelectedItem as string;

            // Get the blank badge XML payload for a badge glyph
            XmlDocument badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeGlyph);

            // Set the value of the badge in the XML to our glyph value
            XmlElement badgeElement = badgeXml.SelectSingleNode("/badge") as XmlElement;
            badgeElement.SetAttribute("value", badgeGlyphValue);

            // Create the badge notification
            BadgeNotification badge = new BadgeNotification(badgeXml);

            // Create the badge updater for our secondary tile, using our tile ID for the secondary tile
            BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile(SECONDARY_TILE_ID);

            // And update the badge
            badgeUpdater.Update(badge);
        }
        private void UpdateLiveTile()
        {
            // build badge
            var type = BadgeTemplateType.BadgeNumber;
            var xml = BadgeUpdateManager.GetTemplateContent(type);

            // update element
            var elements = xml.GetElementsByTagName("badge");
            var element = elements[0] as Windows.Data.Xml.Dom.XmlElement;

            int rnd = new Random().Next(100);

            element.SetAttribute("value", rnd.ToString());

            // send to lock screen
            var updator = BadgeUpdateManager.CreateBadgeUpdaterForApplication();
            var notification = new BadgeNotification(xml);
            updator.Update(notification);

        }
 internal bool HandleBadgeNotification(BadgeNotification badgeNotification)
 {
     // When this happens, a game has just been played and so the myTurnGames is to be
     // updated by one.
     if (badgeUpdater != null)
     {
         if (processor != null)
         {
             // Overwrite the badgeNotification
             var badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);
             var badgeElement = (XmlElement)badgeXml.SelectSingleNode("/badge");
             badgeElement.SetAttribute("value", (processor.MyTurnGames.Count + 1).ToString());
             badgeNotification = new BadgeNotification(badgeXml);
             
         }
         else
             badgeUpdater.Update(badgeNotification);
         return true;
     }
     return false;
 }
        private void SendBadgeNotificationWithStringManipulation_Click(object sender, RoutedEventArgs e)
        {
            Button button = sender as Button;
            if (button != null)
            {
                string badgeXmlString = "<badge value='9'/>";
                Windows.Data.Xml.Dom.XmlDocument badgeDOM = new Windows.Data.Xml.Dom.XmlDocument();
                badgeDOM.LoadXml(badgeXmlString);
                BadgeNotification badge = new BadgeNotification(badgeDOM);

                // Send the notification to the secondary tile
                BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile(MainPage.dynamicTileId).Update(badge);

                rootPage.NotifyUser("Badge notification sent to " + MainPage.dynamicTileId, NotifyType.StatusMessage);
            }
        }
        /// <summary>
        /// 通过Xml磁贴模版文件更新磁贴图标
        /// </summary>
        /// <param name="TileGlyph"></param>
        public static void UpdateBadgeWithGlyphByXml(string tileId, string TileGlyph)
        {


            /*
                            public class TileGlyph
                {
                    public string Name { get; private set; }
                    public bool IsAvailable { get; private set; }
                    public TileGlyph(string name, bool isAvailable)
                    {
                        this.Name = name;
                        this.IsAvailable = isAvailable;
                    }
                    public override string ToString()
                    {
                        return Name;
                    }
                }

                public class TileGlyphCollection : ObservableCollection<TileGlyph>
                {
        
                    public TileGlyphCollection()
                    {
                        // Some glyphs are only available on Windows
            #if WINDOWS_PHONE_APP
                        const bool windows = false;
                        const bool phone = true;
            #else
                        const bool windows = true;
                        const bool phone = false;
            #endif

                        Add(new TileGlyph("none", windows | phone));
                        Add(new TileGlyph("activity", windows));
                        Add(new TileGlyph("alert", windows | phone));
                        Add(new TileGlyph("available", windows));
                        Add(new TileGlyph("away", windows));
                        Add(new TileGlyph("busy", windows));
                        Add(new TileGlyph("newMessage", windows));
                        Add(new TileGlyph("paused", windows));
                        Add(new TileGlyph("playing", windows));
                        Add(new TileGlyph("unavailable", windows));
                        Add(new TileGlyph("error", windows));
                        Add(new TileGlyph("attention", windows | phone));
                        Add(new TileGlyph("alarm", windows));
                    }
                }
                     * */

            // Create a string with the badge template xml.
            string badgeXmlString = "<badge value='" + TileGlyph + "'/>";
            Windows.Data.Xml.Dom.XmlDocument badgeDOM = new Windows.Data.Xml.Dom.XmlDocument();

            // Create a DOM.
            badgeDOM.LoadXml(badgeXmlString);

            // Load the xml string into the DOM, catching any invalid xml characters.
            BadgeNotification badge = new BadgeNotification(badgeDOM);

            // Create a badge notification and send it to the application’s tile.
            BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile(tileId).Update(badge);


        }
        /// <summary>
        /// 通过Xml磁贴模版文件更新磁贴数字
        /// </summary>
        /// <param name="number"></param>
        public static void UpdateSecondaryBadgeWithNumberWithByXml(string tileId, int number)
        {
            // Create a string with the badge template xml.
            string badgeXmlString = "<badge value='" + number + "'/>";
            Windows.Data.Xml.Dom.XmlDocument badgeDOM = new Windows.Data.Xml.Dom.XmlDocument();
            // Create a DOM.
            badgeDOM.LoadXml(badgeXmlString);

            // Load the xml string into the DOM, catching any invalid xml characters.
            BadgeNotification badge = new BadgeNotification(badgeDOM);

            // Create a badge notification and send it to the application’s tile.
            BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile(tileId).Update(badge);
        }
        static public void updateTile(string jSonResponse)
        {

            try
            {
                string bg = "";
                char direction = '-';
                string battery = "";

                JObject response = JObject.Parse(jSonResponse);
                string timeframe = JsonConvert.DeserializeObject(response["bgs"][0]["datetime"].ToString()).ToString();

                bg = response["bgs"][0]["sgv"].ToString();
                battery = response["bgs"][0]["battery"].ToString();


                if (response["bgs"][0]["direction"].ToString().ToLower().Contains("up"))
                    direction = '\x25B2';
                else
                    if (response["bgs"][0]["direction"].ToString().ToLower().Contains("down"))
                    direction = '\x25BC';

                string notification = String.Format("Current bg: {0} \r\nTrend: {1} \r\nBattery: {2}% ", bg, direction.ToString(), battery);

                XmlDocument tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWide310x150Text01);
                XmlNodeList tileTextAttributes = tileXml.GetElementsByTagName("text");
                tileTextAttributes[0].InnerText = notification;

                XmlDocument squareTileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150Text04);
                XmlNodeList squareTileTextAttributes = squareTileXml.GetElementsByTagName("text");
                squareTileTextAttributes[0].AppendChild(squareTileXml.CreateTextNode(notification));
                IXmlNode node = tileXml.ImportNode(squareTileXml.GetElementsByTagName("binding").Item(0), true);
                tileXml.GetElementsByTagName("visual").Item(0).AppendChild(node);

                TileNotification tileNotification = new TileNotification(tileXml);

                tileNotification.ExpirationTime = DateTimeOffset.UtcNow.AddSeconds(100);

                TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification);

                XmlDocument badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeGlyph);
                XmlElement badgeElement = (XmlElement)badgeXml.SelectSingleNode("/badge");
                badgeElement.SetAttribute("value", String.Format("Current bg: {0} \r\nTrend: {1}", bg, direction.ToString()));

                BadgeNotification badge = new BadgeNotification(badgeXml);
                BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badge);

                int reading = System.Int32.Parse(bg);

                if ((reading > 200) || (reading < 80))
                {
                    ToastTemplateType toastTemplate = ToastTemplateType.ToastImageAndText01;
                    XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);
                    XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
                    toastTextElements[0].AppendChild(toastXml.CreateTextNode(String.Format("Current bg: {0} Trend: {1}", bg, direction.ToString())));                   
                                       
                    IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
                    ((XmlElement)toastNode).SetAttribute("duration", "long");
                    XmlElement audio = toastXml.CreateElement("audio");
                    toastNode.AppendChild(audio);
                    
                    ToastNotification toast = new ToastNotification(toastXml);
                    ToastNotificationManager.CreateToastNotifier().Show(toast);
                }
            }
            catch (Exception ex)
            {
                throw;
            }

        }
 /// <summary>
 /// Shows badge notifications in live tile
 /// </summary>
 /// <param name="value">"alert", "activity", "newMessage", "error" or String.Empty/null to clear</param>
 public static void ShowNotificationBadge(string value) 
 {
     if (!string.IsNullOrEmpty(value))
     {
         var badgeXml = Notifications.BadgeUpdateManager.GetTemplateContent(Notifications.BadgeTemplateType.BadgeGlyph);
         var badgeElement = (XmlElement)badgeXml.SelectSingleNode("/badge");
         badgeElement.SetAttribute("value", value);
         var notification = new Notifications.BadgeNotification(badgeXml);
         Notifications.BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(notification);
     }
     else
     {
         Notifications.BadgeUpdateManager.CreateBadgeUpdaterForApplication().Clear();
     }
 }
 public static void ShowNotificationBadge(int value)
 {
     var badgeXml = Notifications.BadgeUpdateManager.GetTemplateContent(Notifications.BadgeTemplateType.BadgeNumber);
     var badgeElement = (XmlElement)badgeXml.SelectSingleNode("/badge");
     badgeElement.SetAttribute("value", value.ToString());
     var notification = new Notifications.BadgeNotification(badgeXml);
     Notifications.BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(notification);
 }