/// <summary> /// 在指定屏幕全屏显示消息通知 /// </summary> /// <param name="title"></param> /// <param name="msg"></param> /// <param name="screenIndex"></param> public static void Notify(string title, string msg, int screenIndex) { if (screenIndex < 0 || screenIndex > System.Windows.Forms.Screen.AllScreens.Length - 1) { screenIndex = Helper.GetPrimaryScreenIndex(); } Application.Current.Dispatcher.Invoke(() => { var bounds = Helper.GetScreenBounds(screenIndex); PopupMaskNotify fullScrBox; lock (_boxes) { fullScrBox = new PopupMaskNotify(); _boxes.Add(fullScrBox); } fullScrBox.Title = title == null ? "" : title; fullScrBox.NotifyContent = msg; fullScrBox.Width = bounds.Width; fullScrBox.Height = bounds.Height; fullScrBox.Left = bounds.X; fullScrBox.Top = bounds.Y; fullScrBox.Opacity = 0; fullScrBox._notifyInfo = new NotifyInfo { IsScreenNotify = true, IsText = true, PlaceTarget = null, ScreenIndex = screenIndex }; fullScrBox.Loaded += (s, e) => { DoubleAnimation aniOpacity = new DoubleAnimation(); aniOpacity.Duration = new Duration(TimeSpan.FromMilliseconds(600)); aniOpacity.To = 1; aniOpacity.EasingFunction = new QuarticEase() { EasingMode = EasingMode.EaseOut }; (s as PopupMaskNotify).BeginAnimation(FrameworkElement.OpacityProperty, aniOpacity); }; fullScrBox.Show(); Task.Factory.StartNew(async(box) => { PopupMaskNotify fbox = box as PopupMaskNotify; await Task.Delay(fbox._lifeMillionSeconds); Application.Current.Dispatcher.Invoke(() => { lock (_boxes) { _boxes.Remove(fbox); } fbox.Close(); }); }, fullScrBox); }); }
static string Loading(object msgContent, object content, FrameworkElement placeTarget, int screenIndex) { return(Application.Current.Dispatcher.Invoke(() => { Rect bounds = placeTarget != null ? Helper.GetElementBounds(placeTarget) : Helper.GetScreenBounds(screenIndex); PopupMaskNotify fullScrBox; lock (_boxes) { fullScrBox = new PopupMaskNotify(); fullScrBox._isWaitingBox = true; _boxes.Add(fullScrBox); } if (content != null) { fullScrBox.Content = content; } else { fullScrBox.rowIcon.Height = new GridLength(10, GridUnitType.Star); fullScrBox.rectWaitingIcon.Visibility = Visibility.Visible; fullScrBox.NotifyContent = msgContent; } fullScrBox.Width = bounds.Width; fullScrBox.Height = bounds.Height; fullScrBox.Left = bounds.X; fullScrBox.Top = bounds.Y; fullScrBox.Opacity = 0; fullScrBox._notifyInfo = new NotifyInfo { IsScreenNotify = placeTarget == null, IsText = msgContent != null, PlaceTarget = placeTarget, ScreenIndex = screenIndex }; if (placeTarget != null) { Window window = Window.GetWindow(placeTarget); fullScrBox._hostWindow = window; if (window != null) { window.StateChanged += fullScrBox.HostWindow_StateChanged; window.LocationChanged += fullScrBox.HostWindow_LocationChanged; window.SizeChanged += fullScrBox.HostWindow_SizeChanged; } } fullScrBox.Loaded += (s, e) => { DoubleAnimation aniOpacity = new DoubleAnimation(); aniOpacity.Duration = new Duration(TimeSpan.FromMilliseconds(600)); aniOpacity.To = 1; aniOpacity.EasingFunction = new QuarticEase() { EasingMode = EasingMode.EaseOut }; (s as PopupMaskNotify).BeginAnimation(FrameworkElement.OpacityProperty, aniOpacity); DoubleAnimation aniRotate = new DoubleAnimation(); aniRotate.Duration = new Duration(TimeSpan.FromMilliseconds(1800)); aniRotate.By = 360; aniRotate.RepeatBehavior = RepeatBehavior.Forever; (s as PopupMaskNotify).rectRotateTransform.BeginAnimation(RotateTransform.AngleProperty, aniRotate); }; fullScrBox.Closed += (s, e) => { var fbox = s as PopupMaskNotify; if (fbox._hostWindow != null) { fbox._hostWindow.StateChanged -= fbox.HostWindow_StateChanged; fbox._hostWindow.LocationChanged -= fbox.HostWindow_LocationChanged; fbox._hostWindow.SizeChanged -= fbox.HostWindow_SizeChanged; } }; fullScrBox.Show(); return fullScrBox.Id; })); }