Exemple #1
0
        private void RemoveNotificationsTimer_OnTick(object sender, EventArgs eventArgs)
        {
            var timer = sender as DispatcherTimer;

            if (timer == null)
            {
                return;
            }

            // Stop the timer and cleanup for GC
            timer.Tick += RemoveNotificationsTimer_OnTick;
            timer.Stop();

            var n = timer.Tag as NotificationViewModel;

            if (n == null)
            {
                return;
            }

            NotificationMessages.Remove(n);

            if (NotificationMessages.Any())
            {
                return;
            }

            InternalStopTimer();
            IsOpen = false;
        }
Exemple #2
0
        public void Show(string message, NotificationType type)
        {
            if (NotificationMessages.Any() == false)
            {
                InternalStartTimer();
                IsOpen = true;
            }

            if (MaximumNotificationCount != UnlimitedNotifications)
            {
                if (NotificationMessages.Count >= MaximumNotificationCount)
                {
                    int removeCount = (int)(NotificationMessages.Count - MaximumNotificationCount) + 1;

                    var itemsToRemove = NotificationMessages.OrderBy(x => x.CreateTime)
                                        .Take(removeCount)
                                        .Select(x => x.Id)
                                        .ToList();
                    foreach (var id in itemsToRemove)
                    {
                        Hide(id);
                    }
                }
            }

            NotificationMessages.Add(new NotificationViewModel
            {
                Message = message,
                Type    = type
            });
        }
Exemple #3
0
        public void Hide(Guid id)
        {
            var n = NotificationMessages.SingleOrDefault(x => x.Id == id);

            if (n?.InvokeHideAnimation == null)
            {
                return;
            }

            n.InvokeHideAnimation();

            Task.Factory.StartNew(() =>
            {
                Thread.Sleep(200);
            }).ContinueWith(t =>
            {
                NotificationMessages.Remove(n);

                if (NotificationMessages.Any() == false)
                {
                    InternalStopTimer();
                    IsOpen = false;
                }
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }