Inheritance: System.Windows.Controls.UserControl
コード例 #1
0
        private void HandleCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == NotifyCollectionChangedAction.Add)
            {
                var replaceExisting = false;
                var minWidth = 0.0;

                if (currentNotification != null)
                {
                    minWidth = currentNotification.ActualWidth;
                    replaceExisting = true;
                    RemoveOldNotification();
                }

                var item = e.NewItems[0] as Notification;

                currentNotification = new NotificationView() { DataContext = item, MinWidth = minWidth};
                currentNotification.MouseLeftButtonUp +=
                    delegate { if (currentNotification != null) RemoveOldNotification(); };

                LayoutRoot.Children.Add(currentNotification);
                currentNotification.Display(replaceExisting);

                if (item != null && item.Level == NotificationLevel.Error)
                {
                    timer.Interval = TimeSpan.FromSeconds(6);
                }
                else
                {
                    timer.Interval = TimeSpan.FromSeconds(3);
                }

                timer.Start();
            }
        }
コード例 #2
0
        private void RemoveOldNotification()
        {
            var oldView = currentNotification;

            oldView.Hide(() => LayoutRoot.Children.Remove(oldView));

            currentNotification = null;
            timer.Stop();
        }