Example #1
0
        public void RemoveNotification(string group)
        {
            Notification existing = _notifications.FirstOrDefault(n => String.Equals(n.Group, group, StringComparison.InvariantCultureIgnoreCase));

            if (existing == null)
            {
                return;
            }

            VanishingContainer container = GetContainer(existing);

            container.Vanish(TimeSpan.Zero);
        }
        public void AddNotification(object content, TimeSpan duration, string group = null)
        {
            if (!CheckAccess())
            {
                Dispatcher.BeginInvoke(new Action(() =>
                {
                    AddNotification(content, duration, group);
                }));
                return;
            }

            Notification existing = null;

            if (!string.IsNullOrWhiteSpace(group))
            {
                existing = _notifications.FirstOrDefault(n => String.Equals(n.Group, group, StringComparison.InvariantCultureIgnoreCase));
            }


            if (existing != null)
            {
                existing.Content = content;

                VanishingContainer container = GetContainer(existing);
                container.Vanish(duration);
            }
            else
            {
                var newNotification = new Notification
                {
                    Group   = group,
                    Content = content
                };

                _notifications.Add(newNotification);

                VanishingContainer control = new VanishingContainer {
                    Content = newNotification
                };
                control.Gone += ControlOnGone;
                AddChild(control);
                control.Vanish(duration);
            }
        }