コード例 #1
0
        public NotifyControl(NotificationOption notificationOption, ObservableCollection <NotificationOption> baseCollection)
        {
            _baseCollection = baseCollection;
            InitializeComponent();
            DataContext = notificationOption;
            ViewModel   = notificationOption;

            if (notificationOption.IsEmpty)
            {
                _baseCollection.Remove(notificationOption);
                this.Visibility = Visibility.Collapsed;
                return;
            }

            switch (notificationOption.Level)
            {
            case NotificationLevel.Normal:
                BoxFlag.Fill = Brushes.Transparent;
                break;

            case NotificationLevel.Warn:
                BoxFlag.Fill = (Brush)FindResource("OrangeBrush");
                break;

            case NotificationLevel.Error:
                BoxFlag.Fill = (Brush)FindResource("RedBrush");
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            if (notificationOption.Type == NotificationType.Alert &&
                notificationOption.FadeoutTime > TimeSpan.FromSeconds(1))
            {
                _timer = new Timer(obj =>
                {
                    Dispatcher.Invoke(TriggerHide);
                    _timer?.Dispose();
                }, null, (int)notificationOption.FadeoutTime.TotalMilliseconds, Timeout.Infinite);
            }
        }
コード例 #2
0
 public static void Push(NotificationOption notification)
 {
     Execute.ToUiThread(() => { NotificationList?.Add(notification); });
 }