In code, this can be done using
private void button1_Click(object sender, RoutedEventArgs e)
{
ColorAnimation ca = new ColorAnimation(Colors.Red, Colors.Blue, new Duration(TimeSpan.FromSeconds(4)));
Storyboard.SetTarget(ca, this);
Storyboard.SetTargetProperty(ca, new PropertyPath("Background.Color"));
Storyboard stb = new Storyboard();
stb.Children.Add(ca);
stb.Begin();
}
As HB noted, this will work too.
private void button1_Click(object sender, RoutedEventArgs e)
{
ColorAnimation ca = new ColorAnimation(Colors.Blue, new Duration(TimeSpan.FromSeconds(4)));
this.Background = new SolidColorBrush(Colors.Red);
this.Background.BeginAnimation(SolidColorBrush.ColorProperty, ca);
}
source
share