I have an application that needs to give status updates, but they're pretty easy to miss. I want to very lightly and very briefly pulse the status bar when messages are posted. Almost every guide I've seen so far only lists how to set it up on hover or click using XAML instead of actual C#. I want to call a function to pulse the bar when I'm updating status messages in C#:
This is what I have and it doesn't work at all.
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);
}
CodePudding user response:
I tried it and i found some mistakes. It has nothing todo with XAML as everything that can be written in XAML can be written in C# as well.
However:
First you want to animate the Color property of the SolidBrush object. And second, at least in my try i could not animate the pre set background brush of the wrap panel (it said it was "sealed"). You might also want to set the RepeatBehavior to Forever, to keep the animation running.
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);
CodePudding user response:
Do you need to do a Form.refresh between making the change and reversing it?