Add RotateTransform animation to Storyboard encoded

I have the following animation defined in the code:

DoubleAnimation dbAscending = new DoubleAnimation(0, 15, new Duration(TimeSpan.FromMilliseconds(300))); (myImage.RenderTransform as RotateTransform).BeginAnimation(RotateTransform.AngleProperty, dbAscending); 

This works great, when it starts, it rotates myImage by 15 degrees. Now I just need to create a new Storyboard and add animation to it, because I need to use its Completed event. I have a little problem with this, I noticed that I can add animation to Storyboard.Children , but I was not able to define the object and property to which I want to apply this animation to ...

Thanks in advance for any help, so far I have created storyboards only in XAML ...

+4
source share
1 answer

You need to set the animation properties associated with the storyboard, for example:

 DoubleAnimation dbAscending = new DoubleAnimation(0, 15, new Duration(TimeSpan.FromMilliseconds(300))); Storyboard storyboard = new Storyboard(); storyboard.Children.Add(dbAscending); Storyboard.SetTarget(dbAscending, myImage); Storyboard.SetTargetProperty(dbAscending, new PropertyPath("RenderTransform.Angle")); 

(untested; can also directly target the transform and reduce the path to an angle)

+7
source

All Articles