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.
Asked
Active
Viewed 178 times
1

McGarnagle
- 101,349
- 31
- 229
- 260
-
Please answer this question. – Jan 06 '15 at 04:14
-
Could you please suggest me how to set the animation in WinRT in code behind – Jan 08 '15 at 09:49
1 Answers
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