脉冲状态消息背后的背景,使它们更加可见 - Csharp WPF
Pulse the background behind status messages to make them more visible - 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);
我有一个应用程序需要提供状态更新,但很容易错过。当发布消息时,我想非常轻微和非常短暂地脉冲状态栏。到目前为止,我看到的几乎所有指南都只列出了如何使用 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);