脉冲状态消息背后的背景,使它们更可见-Csharp WPF



我有一个应用程序需要提供状态更新,但它们很容易被错过。我想在发布消息时非常轻松、非常短暂地触发状态栏。到目前为止,我看到的几乎每一本指南都只列出了如何使用XAML而不是实际的C#在悬停或单击时设置它。当我在C#中更新状态消息时,我想调用一个函数来脉冲条:

这就是我所拥有的,但它根本不起作用。

private void PulseStatus()
{   
ColorAnimation animation;
animation = new ColorAnimation();
animation.To = Color.FromRgb(111, 80, 80);
animation.Duration = new Duration(TimeSpan.FromSeconds(.4));
animation.AutoReverse =true;
StatusArea.Background.BeginAnimation(WrapPanel.BackgroundProperty,animation);
}

我试过了,发现了一些错误。它与XAML无关,因为所有可以用XAML编写的东西都可以用C#编写。

但是:

首先要设置SolidBrush对象的"颜色"特性的动画。第二,至少在我的尝试中,我无法为包装面板的预设背景刷设置动画(它说它是"密封的"(。您可能还希望将"RepeatBehavior"设置为"Forever",以保持动画运行。

ColorAnimation animation;
animation = new ColorAnimation();
animation.To = Color.FromRgb(111, 80, 80);
animation.Duration = new Duration(TimeSpan.FromSeconds(.4));
animation.AutoReverse = true;
animation.RepeatBehavior = RepeatBehavior.Forever;

var clonedBackgroundBrush = wrap.Background.Clone();
wrap.Background = clonedBackgroundBrush;
clonedBackgroundBrush.BeginAnimation(SolidColorBrush.ColorProperty, animation);

最新更新