public static void NotifyCustom(object content, FrameworkElement placeTarget) { Application.Current.Dispatcher.Invoke(() => { PopupNotify bx = new PopupNotify(); DependencyPropertyDescriptor.FromProperty(ActualWidthProperty, typeof(FrameworkElement)).AddValueChanged(bx, (sender, e) => { (sender as PopupNotify).Left = CalcElementRight(placeTarget) - (sender as PopupNotify).ActualWidth; }); DependencyPropertyDescriptor.FromProperty(ActualHeightProperty, typeof(FrameworkElement)).AddValueChanged(bx, (sender, e) => { (sender as PopupNotify).Top = (sender as PopupNotify)._bottom - (sender as PopupNotify).ActualHeight; }); bx.Content = content; bx.Title = ""; bx._bottom = CalcBoxBottom(placeTarget); bx._notifyInfo = new NotifyInfo { IsScreenNotify = false, IsText = false, PlaceTarget = placeTarget }; lock (_boxes) { _boxes.Add(bx); } bx.Loaded += (s, e) => { PopupNotify self = s as PopupNotify; self.UpdateLayout(); SystemSounds.Asterisk.Play();//播放提示声 self.Top = self._bottom - self.ActualHeight; self.Left = CalcElementRight(self._notifyInfo.PlaceTarget) - self.ActualWidth; if (self.Top < 0) { self.Visibility = Visibility.Hidden; } else { FadeIn(self); Task.Factory.StartNew((box1) => { System.Threading.Thread.Sleep(TimeSpan.FromMilliseconds(_boxLife)); lock (_boxes) { if (_boxes.Contains(box1)) { Application.Current.Dispatcher.Invoke(() => { FadeOut(box1 as PopupNotify); }); } } }, self); } }; bx.Show(); }); }
/// <summary> /// 显示消息提示(指定屏幕的右下角 /// </summary> /// <param name="content">消息内容</param> /// <param name="title">消息标题</param> /// <param name="screenIndex">屏幕序号</param> public static void Notify(DependencyObject content, string title, int screenIndex) { Application.Current.Dispatcher.Invoke(() => { PopupNotify bx = new PopupNotify(); DependencyPropertyDescriptor.FromProperty(ActualWidthProperty, typeof(FrameworkElement)).AddValueChanged(bx, (sender, e) => { (sender as PopupNotify).Left = GetScrRight(screenIndex) - (sender as PopupNotify).ActualWidth; }); DependencyPropertyDescriptor.FromProperty(ActualHeightProperty, typeof(FrameworkElement)).AddValueChanged(bx, (sender, e) => { (sender as PopupNotify).Top = (sender as PopupNotify)._bottom - (sender as PopupNotify).ActualHeight; }); bx.MessageObj = content; bx.Title = title == null ? "" : title; bx._bottom = CalcBoxBottom(screenIndex); bx._notifyInfo = new NotifyInfo { IsScreenNotify = true, IsText = false, ScreenIndex = screenIndex }; lock (_boxes) { _boxes.Add(bx); } bx.Loaded += (s, e) => { try { PopupNotify self = s as PopupNotify; self.UpdateLayout(); SystemSounds.Asterisk.Play();//播放提示声 self.Top = self._bottom - self.ActualHeight; self.Left = GetScrRight(screenIndex) - self.ActualWidth; if (self.Top < 0) { self.Visibility = Visibility.Hidden; } else { FadeIn(self); Task.Factory.StartNew((box1) => { System.Threading.Thread.Sleep(TimeSpan.FromMilliseconds(_boxLife)); Application.Current.Dispatcher.Invoke(() => { FadeOut(box1 as PopupNotify); }); }, self); } } catch (Exception ex) { } }; bx.Show(); }); }