/// <summary> /// Set badge counter for application with given id. /// </summary> /// <param name="appId">ID of the application.</param> /// <param name="badgeCount">New counter value.</param> public void SetBadge(string appId, int badgeCount) { try { BadgeControl.Add(new Badge(appId, badgeCount, true)); } catch (Exception e) { Debug.WriteLine($"Error setting badge for {appId}: {e.Message}"); } }
/// <summary> /// Set the number of events or notifications to show on the badge. /// </summary> /// <param name="count">Number of events or notifications</param> public static void SetCount(uint count) { if (_badge == null) { try { _badge = BadgeControl.Find(_appId); } catch (InvalidOperationException) { // An exception is thrown when the app tries to access a badge before it is added. _badge = new Badge(_appId, count: 0, visible: true); BadgeControl.Add(_badge); } } _badge.Count = (int)count; BadgeControl.Update(_badge); }
public void SetBadge(int?value) { var appId = Application.Current.ApplicationInfo.ApplicationId; try { BadgeControl.Remove(appId); } catch (InvalidOperationException) { // This exception is thrown when the badge does not exist. // Seems there is no way to check if the badge exists. } if (value != null) { Badge badge = new Badge(appId, value.Value); BadgeControl.Add(badge); } }
/// <summary> /// This Function sets badge value of current application to BadgeValue. /// </summary> private void ApplyBadge() { Badge current = GetBadge(); try { if (current == null) { BadgeControl.Add(new Badge(applicationId, BadgeValue)); } else { current.Count = BadgeValue; current.Visible = true; BadgeControl.Update(current); } } catch (Exception e) { Log.Debug("Badges", $"Failed to set badge count. {e.GetType()}, {e.Message}"); } }