public void ShowMessage(string message, bool isSuccess = true) { if (message == string.Empty) { return; } MessageBar.Visibility = Visibility.Visible; MessageBarContent.Text = message; MessageBar.Background = isSuccess ? Utils.Colors.Green : Utils.Colors.Red; // 显示动画 DoubleAnimation showAnimation = new DoubleAnimation { From = 0, To = 1, Duration = new Duration(TimeSpan.FromSeconds(.4)) }; // 消失动画 DoubleAnimation hiddenAnimation = new DoubleAnimation { From = 1, To = 0, Duration = new Duration(TimeSpan.FromSeconds(2)) }; // 显示动画执行完毕后执行消失动画 showAnimation.Completed += new EventHandler((object a, EventArgs b) => { MessageBar.BeginAnimation(OpacityProperty, hiddenAnimation); }); // 消失动画执行完毕后隐藏消息通知 hiddenAnimation.Completed += new EventHandler((object a, EventArgs b) => { MessageBar.Visibility = Visibility.Collapsed; }); MessageBar.BeginAnimation(OpacityProperty, hiddenAnimation); }