2011-05-02 65 views
4

至脚本我在后台代码中定义的下面的动画:添加RotateTransform动画代码隐藏

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

这工作得很好,当它开始旋转myImage 15度。现在我只需要创建新的Storyboard并添加动画,因为我需要使用它的Completed事件。我有一个小问题,我注意到我可以将动画添加到Storyboard.Children,但我没有设法定义我想要应用此动画的对象和属性...

在此先感谢您帮助,到现在为止我只在XAML创建故事板...

回答

7

您需要设置上的动画故事板,附加属性,是这样的:

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")); 

未经检验,也可以直接针对变换并减小路径角度