//--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\ #region --Misc Methods (Public)-- public static void IncBadgeCount() { // 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; string value = null; try { value = badgeElement.GetAttribute("value"); } catch (Exception) { Logger.Debug("Failed to retrieve badge count value node."); } if (int.TryParse(value, out int count)) { badgeElement.SetAttribute("value", (count + 1).ToString()); } else { badgeElement.SetAttribute("value", "1"); } // 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); }
private static void UpdateBadgeGlyph(string badgeGlyphValue) { //https://docs.microsoft.com/en-us/windows/uwp/controls-and-patterns/tiles-and-notifications-badges if (badgeGlyphValue.IsNullOrWhiteSpace()) { badgeGlyphValue = "alert"; } // 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 the application BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForApplication(); // And update the badge badgeUpdater.Update(badge); }
private void SetState(StateType state) { BadgeUpdateManager.CreateBadgeUpdaterForApplication().Clear(); string badgeGlyphValue = ""; switch (state) { case StateType.available: badgeGlyphValue = "available"; break; case StateType.away: badgeGlyphValue = "away"; break; case StateType.busy: badgeGlyphValue = "busy"; break; default: break; } XmlDocument badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeGlyph); XmlElement badgeElement = badgeXml.SelectSingleNode("/badge") as XmlElement; badgeElement.SetAttribute("value", badgeGlyphValue); BadgeNotification badge = new BadgeNotification(badgeXml); BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForApplication(); badgeUpdater.Update(badge); }
private async void ButtonUpdateBadgeNumber_Click(object sender, RoutedEventArgs e) { int num; if (!int.TryParse(TextBoxBadgeNumber.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 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); }
public static void UpdateBadgeGlyph(BadgeGlyph glyph) { // Create the badge updater for the application BadgeUpdater updater = BadgeUpdateManager.CreateBadgeUpdaterForApplication(); if (glyph == BadgeGlyph.None) { updater.Clear(); } else { // Get the blank badge XML payload for a badge number XmlDocument badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeGlyph); // Set the value of the badge in the xml to our number XmlElement badgeElem = badgeXml.SelectSingleNode("/badge") as XmlElement; badgeElem.SetAttribute("value", glyph.DescriptionAttr()); // Create the badge notification BadgeNotification badge = new BadgeNotification(badgeXml) { ExpirationTime = DateTimeOffset.UtcNow.AddMinutes(10) }; // And update the badge updater.Update(badge); } }
public void UpdateCount(int count) { var badgeXml = TileHelper.CreateBadgeNumber(count); var badge = new BadgeNotification(badgeXml); _badgeUpdater.Update(badge); }
private void OnSetBadgeClick(object sender, RoutedEventArgs e) { var template = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber); (template.GetElementsByTagName("badge")[0] as XmlElement).SetAttribute("value", countTextBox.Text); BadgeUpdater updater = BadgeUpdateManager.CreateBadgeUpdaterForApplication(); updater.Update(new BadgeNotification(template)); }
public void UpdateBadge() { var badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber); var badgeAttributes = badgeXml.GetElementsByTagName("badge"); bool clearValue = false; if (errorState) { badgeAttributes[0].Attributes.GetNamedItem("value").NodeValue = "error"; } else if (NotificationCount > 0) { badgeAttributes[0].Attributes.GetNamedItem("value").NodeValue = NotificationCount.ToString(); } else if (new Accounts().Enabled.Count() <= 0) { clearValue = true; } else { var status = new Status(); string value = ""; switch (status.status) { case StatusType.Available: value = "available"; break; case StatusType.Away: value = "away"; break; case StatusType.Busy: value = "busy"; break; case StatusType.Offline: value = "unavailable"; break; } badgeAttributes[0].Attributes.GetNamedItem("value").NodeValue = value; } if (clearValue) { BadgeUpdater.Clear(); } else { BadgeUpdater.Update(new BadgeNotification(badgeXml)); } }
private void setBadgeNumber(int num) { XmlDocument badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber); XmlElement badgeElement = badgeXml.SelectSingleNode("/badge") as XmlElement; badgeElement.SetAttribute("value", num.ToString()); BadgeNotification badge = new BadgeNotification(badgeXml); BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForApplication(); badgeUpdater.Update(badge); }
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; }
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); }
public static void SetBadgeNum(double num) { BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForApplication(); badgeUpdater.Clear(); if (num != 0) { XmlDocument xml = new XmlDocument(); xml.LoadXml($"<badge value=\"{num}\"/>"); badgeUpdater.Update(new BadgeNotification(xml)); } }
public static async void UpdateBadge(int count) { await Task.Run(() => { Debug.WriteLine("更新 badge 数量 开始"); XmlDocument badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber); XmlElement badgeElement = (XmlElement)badgeXml.SelectSingleNode("/badge"); badgeElement.SetAttribute("value", count.ToString()); BadgeNotification badgeNotification = new BadgeNotification(badgeXml); BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForApplication(); badgeUpdater.Update(badgeNotification); Debug.WriteLine(string.Format("更新 badge 数量 {0} 结束", count)); }); }
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); }
public void Run(IBackgroundTaskInstance taskInstance) { BackgroundTaskDeferral deferral = taskInstance.GetDeferral(); Random randomizer = new Random(); var template = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber); (template.GetElementsByTagName("badge")[0] as XmlElement).SetAttribute("value", randomizer.Next(1, 99).ToString()); BadgeUpdater updater = BadgeUpdateManager.CreateBadgeUpdaterForApplication(); updater.Update(new BadgeNotification(template)); deferral.Complete(); }
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); }
private void setBadgeNumber(int num) { // 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); }
void UpdateBadge() { Debug.WriteLine("更新 badge 数量 开始"); int count = GetNoticeCountFromNoticeToastTempData(); count += GetPmCountFromPmToastTempData(); XmlDocument badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber); XmlElement badgeElement = (XmlElement)badgeXml.SelectSingleNode("/badge"); badgeElement.SetAttribute("value", count.ToString()); BadgeNotification badgeNotification = new BadgeNotification(badgeXml); BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForApplication(); badgeUpdater.Update(badgeNotification); Debug.WriteLine(string.Format("更新 badge 数量 {0} 结束", count)); }
// 发送 Application 的 Badge 通知 private void btnBadgeNotification_Click(object sender, RoutedEventArgs e) { // 用于描述 badge 通知的 xml 字符串(数字在 1 - 99 之间,如果大于 99 则会显示 99+ ,如果是 0 则会移除 badge,如果小于 0 则无效) string badgeXml = "<badge value='3'/>"; // 将 xml 字符串转换为 Windows.Data.Xml.Dom.XmlDocument 对象 XmlDocument badgeDoc = new XmlDocument(); badgeDoc.LoadXml(badgeXml); // 实例化 BadgeNotification 对象 BadgeNotification badgeNotification = new BadgeNotification(badgeDoc); // 将指定的 BadgeNotification 对象更新到 application BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForApplication(); badgeUpdater.Update(badgeNotification); }
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 the application BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForApplication(); // And update the badge badgeUpdater.Update(badge); }
/// <summary> /// Updates the badge with the number of unread emails. /// </summary> /// <param name="number">The number of unread emails.</param> public static void UpdateBadge(int number) { try { // create a string with the badge template xml string badgeXmlString = string.Format("<badge value='{0}'/>", number); XmlDocument badgeDOM = new 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 _badgeUpdater.Update(badge); } catch (Exception ex) { LogFile.Instance.LogError("", "", ex.ToString()); } }
private void SetBadgeValue(BadgeUpdater badgeUpdater, int value) { // create a string with the badge template xml string badgeXmlString = string.Format("<badge value='{0}'/>", value); XmlDocument badgeDOM = new XmlDocument(); try { // 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 badgeUpdater.Update(badge); } catch (Exception ex) { TrackingManagerHelper.Exception(ex, $"Set badge error loading xml: {badgeXmlString}"); } }
// 以数字的方式更新 Application Badge 通知 private void btnUpdateBadgeWidthNumber_Click(object sender, RoutedEventArgs e) { // 用于描述 badge 通知的 xml 字符串(数字在 1 - 99 之间,如果大于 99 则会显示 99+ ,如果是 0 则会移除 badge,如果小于 0 则无效) string badgeXml = "<badge value='6'/>"; // 将 xml 字符串转换为 Windows.Data.Xml.Dom.XmlDocument 对象 XmlDocument badgeDoc = new XmlDocument(); badgeDoc.LoadXml(badgeXml); // 获取此 badge 的 xml // lblMsg.Text = badgeXml.GetXml(); // 实例化 BadgeNotification 对象 BadgeNotification badgeNotification = new BadgeNotification(badgeDoc); DateTimeOffset expirationTime = DateTimeOffset.UtcNow.AddSeconds(30); badgeNotification.ExpirationTime = expirationTime; // 30 秒后清除这个 badge // 将指定的 BadgeNotification 对象更新到 application BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForApplication(); badgeUpdater.Update(badgeNotification); }
// 以图标的方式更新 Application Badge 通知 private void btnUpdateBadgeWidthIcon_Click(object sender, RoutedEventArgs e) { // 用于描述 badge 通知的 xml 字符串 string badgeXml = $"<badge value='{((ComboBoxItem)cmbBadgeValue.SelectedItem).Content}'/>"; // 将 xml 字符串转换为 Windows.Data.Xml.Dom.XmlDocument 对象 XmlDocument badgeDoc = new XmlDocument(); badgeDoc.LoadXml(badgeXml); // 获取此 badge 的 xml // lblMsg.Text = badgeXml.GetXml(); // 实例化 BadgeNotification 对象 BadgeNotification badgeNotification = new BadgeNotification(badgeDoc); DateTimeOffset expirationTime = DateTimeOffset.UtcNow.AddSeconds(30); badgeNotification.ExpirationTime = expirationTime; // 30 秒后清除这个 badge // 将指定的 BadgeNotification 对象更新到 application BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForApplication(); badgeUpdater.Update(badgeNotification); }
public void Update() { try { var unread = _discord.Guilds.Values.Any(g => g.Unread); if (!unread) { return; } var badgeNumber = _discord.Guilds.Values.Sum(g => g.MentionCount) + _discord.PrivateChannels.Values.Sum(g => g.ReadState?.MentionCount); if (badgeNumber != 0) { var badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber); var badgeElement = badgeXml.SelectSingleNode("/badge") as XmlElement; badgeElement.SetAttribute("value", badgeNumber.ToString()); _badgeUpdateManager.Update(new BadgeNotification(badgeXml)); } //else if (unread) //{ // var badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeGlyph); // var badgeElement = badgeXml.SelectSingleNode("/badge") as XmlElement; // badgeElement.SetAttribute("value", "available"); // _badgeUpdateManager.Update(new BadgeNotification(badgeXml)); //} else { _badgeUpdateManager.Clear(); } } catch (Exception) { // TODO: log } }
/// <summary> /// Creates or updates one or multiple live tiles on the executing platform. How it is manifests itself is determined by the class that /// implements this interface. If the platform does not support this feature, then the implementation should do nothing. /// </summary> /// <param name="model">Model which contains the data necessary to create a new tile or to find the tile to update</param> public override async Task <bool> CreateOrUpdateTileAsync(IModel model) { if (model == null) { return(false); } // Do custom tile creation based on the type of the model passed into this method. if (model is MainViewModel || model is ModelList <ItemModel> ) { var list = (model as MainViewModel)?.Items ?? model as ModelList <ItemModel>; // 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", list?.Count.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); } else if (model is ItemModel) { var item = model as ItemModel; var tile = new SecondaryTile(); tile.TileId = Platform.Current.GenerateModelTileID(item); tile.Arguments = Platform.Current.GenerateModelArguments(model); tile.DisplayName = item.LineOne; var status = await this.CreateOrUpdateSecondaryTileAsync(tile, new TileVisualOptions()); if (status) { #region Create ItemModel TileContent // Construct the tile content TileContent content = new TileContent() { Visual = new TileVisual() { TileMedium = new TileBinding() { Content = new TileBindingContentAdaptive() { Children = { new TileText() { Text = item.LineOne }, new TileText() { Text = item.LineTwo, Style = TileTextStyle.CaptionSubtle }, new TileText() { Text = item.LineThree, Style = TileTextStyle.CaptionSubtle } } } }, TileWide = new TileBinding() { Content = new TileBindingContentAdaptive() { Children = { new TileText() { Text = item.LineOne, Style = TileTextStyle.Subtitle }, new TileText() { Text = item.LineTwo, Style = TileTextStyle.CaptionSubtle }, new TileText() { Text = item.LineThree, Style = TileTextStyle.CaptionSubtle } } } }, TileLarge = new TileBinding() { Content = new TileBindingContentAdaptive() { Children = { new TileText() { Text = item.LineOne, Style = TileTextStyle.Subtitle }, new TileText() { Text = item.LineTwo, Style = TileTextStyle.CaptionSubtle }, new TileText() { Text = item.LineThree, Style = TileTextStyle.CaptionSubtle } } } } } }; #endregion var notification = new TileNotification(content.GetXml()); notification.ExpirationTime = DateTimeOffset.UtcNow.AddMinutes(10); TileUpdateManager.CreateTileUpdaterForSecondaryTile(tile.TileId).Update(notification); } return(status); } return(false); }