예제 #1
0
        public async void ShowNotification(AppNotification notification)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                if (notification.IsHided)
                {
                    return;
                }

                if (_notificationsPanel == null)
                {
                    _waitingNotifications.Add(notification);
                    return;
                }

                var anc = new AppNotificationControl()
                {
                    Message = notification
                };
                anc.Loaded += (s, e) => anc.Show();
                anc.Tapped += (s, e) =>
                {
                    anc.Hide();
                    if (!String.IsNullOrWhiteSpace(anc.Message.DestinationView))
                    {
                        _navigationService.Value.Navigate(anc.Message.DestinationView, anc.Message.NavigationParameter);
                    }

                    anc.Message.ActionToDo?.Invoke();
                };
                notification.HideRequested += (s, e) => anc.Hide();
                _notificationsPanel.Children.Insert(0, anc);
            });
        }
예제 #2
0
        public async void ShowNotification(AppNotification notification)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                if (notification.IsHided)
                {
                    return;
                }

                if (NotificationsPanel == null)
                {
                    lock (_lockObject)
                    {
                        _waitingNotifications.Add(notification);
                        if (_waitingNotifications.Count >= 5)
                        {
                            _waitingNotifications.RemoveAt(0);
                        }

                        return;
                    }
                }

                var anc = new AppNotificationControl {
                    Message = notification
                };
                anc.Loaded += (s, e) => anc.Show();
                anc.Tapped += (s, e) =>
                {
                    lock (_lockObject)
                        _notificationsCount--;

                    anc.Hide();
                    if (!String.IsNullOrWhiteSpace(anc.Message.DestinationView))
                    {
                        _navigationService.Navigate(anc.Message.DestinationView, anc.Message.NavigationParameter);
                    }

                    anc.Message.ActionToDo?.Invoke();
                };
                notification.HideRequested += (s, e) =>
                {
                    lock (_lockObject)
                        _notificationsCount--;
                    anc.Hide();
                };

                lock (_lockObject)
                {
                    NotificationsPanel.Children.Insert(0, anc);
                    _notificationsCount++;

                    if (_notificationsCount >= 5)
                    {
                        //var notificationControl = NotificationsPanel.Children.LastOrDefault() as AppNotificationControl;
                        NotificationsPanel.Children.RemoveAt(NotificationsPanel.Children.Count - 1);
                        _notificationsCount--;
                    }
                }

                Debug.WriteLine($"Count: {_notificationsCount}");
            });
        }