public void AddNotification(string title, string content) { if (!string.IsNullOrEmpty(title) && !string.IsNullOrEmpty(content)) { NotificationWindow dialog = new NotificationWindow() { m_Title = title, m_Content = content }; EventHandler _EventHandler = (senderobj, obj) => { var closedDialog = senderobj as NotificationWindow; RemoveNotification(closedDialog); }; dialog.Closed += _EventHandler; dialog.TopFrom = GetTopFrom(); AddNotification(dialog); dialog.Show(); } }
private void NotificationWindow_Loaded(object sender, RoutedEventArgs e) { tbContent.Text = m_Content; tbTitle.Text = m_Title; NotificationWindow self = sender as NotificationWindow; if (self != null) { self.UpdateLayout(); SystemSounds.Asterisk.Play(); //播放提示声 double right = System.Windows.SystemParameters.WorkArea.Right; //工作区最右边的值 self.Top = self.TopFrom - self.ActualHeight; DoubleAnimation animation = new DoubleAnimation(); animation.Duration = new Duration(TimeSpan.FromMilliseconds(500)); //NotifyTimeSpan是自己定义的一个int型变量,用来设置动画的持续时间 animation.From = right; animation.To = right - self.ActualWidth; //设定通知从右往左弹出 self.BeginAnimation(Window.LeftProperty, animation); //设定动画应用于窗体的Left属性 Task.Factory.StartNew(delegate { int seconds = 5;//通知持续5s后消失 System.Threading.Thread.Sleep(TimeSpan.FromSeconds(seconds)); //Invoke到主进程中去执行 this.Dispatcher.Invoke(delegate { animation = new DoubleAnimation(); animation.Duration = new Duration(TimeSpan.FromMilliseconds(500)); animation.Completed += (s, a) => { self.Close(); }; //动画执行完毕,关闭当前窗体 animation.From = right - self.ActualWidth; animation.To = right; //通知从左往右收回 self.BeginAnimation(Window.LeftProperty, animation); }); }); } }
public bool RemoveNotification(NotificationWindow dialog) { _dialogs.Remove(dialog); return(true); }
public bool AddNotification(NotificationWindow dialog) { _dialogs.Add(dialog); return(true); }