/// <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); }
/// <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}"); } }