1

In WPF we can animate the back ground color for the particular control by using below code: AssociatedObject.Background.BeginAnimation(SolidColorBrush.ColorProperty, ColorAnimation); But I don't know how to animate the same in Silverlight and WinRT platforms.

McGarnagle
  • 101,349
  • 31
  • 229
  • 260

1 Answers1

0

The WPF code is (I think?) a shorthand for creating a storyboard, adding an animation and assigning its target, and running the storyboard. You can do the same in Silverlight like this:

var animation = new ColorAnimation 
{
    To = Colors.Black,
    Duration = new Duration(TimeSpan.FromMilliseconds(500))
};

Storyboard.SetTarget(animation, AssociatedObject.Background);
Storyboard.SetTargetProperty(animation, new PropertyPath(SolidColorBrush.ColorProperty));

var sb = new Storyboard();
sb.Children.Add(animation);
sb.Begin();
McGarnagle
  • 101,349
  • 31
  • 229
  • 260
  • I tried this but i got the exception "Element is already the child of another element". how can achieve my requirement. –  Jan 07 '15 at 09:45
  • If i set the DataContext for that particular control i got the exception."Operation is not valid on an active Animation or Storyboard. Root Storyboard must be stopped first." Could you please help me how can i solve this problem and achieve my requirement. –  Jan 09 '15 at 04:12