void NoticeWindow_Loaded(object sender, RoutedEventArgs e) { tbx_msg.Text = MSG; NoticeWindow self = sender as NoticeWindow; if (self != null) { self.UpdateLayout(); SystemSounds.Asterisk.Play();//播放提示聲 self.Top = 10 + self.ActualHeight; DoubleAnimation animation = new DoubleAnimation(); animation.Duration = new Duration(TimeSpan.FromMilliseconds(500)); animation.From = SystemParameters.WorkArea.Bottom; animation.To = SystemParameters.WorkArea.Bottom - self.ActualHeight; self.BeginAnimation(Window.TopProperty, animation); Task.Factory.StartNew(delegate { System.Threading.Thread.Sleep(TimeSpan.FromSeconds(5));//通知持續5s後消失 System.Windows.Application.Current.Dispatcher.Invoke( new Action(() => { animation = new DoubleAnimation(); animation.Duration = new Duration(TimeSpan.FromMilliseconds(500)); animation.Completed += (s, a) => { self.Close(); };//動畫執行完畢,關閉當前窗體 animation.From = SystemParameters.WorkArea.Bottom - self.ActualHeight; animation.To = SystemParameters.WorkArea.Bottom; self.BeginAnimation(Window.TopProperty, animation); })); }); } } }