Ond*_* C. 4 c# wpf animation storyboard
我在代码隐藏中定义了以下动画:
DoubleAnimation dbAscending = new DoubleAnimation(0, 15, new Duration(TimeSpan.FromMilliseconds(300)));
(myImage.RenderTransform as RotateTransform).BeginAnimation(RotateTransform.AngleProperty, dbAscending);
Run Code Online (Sandbox Code Playgroud)
这工作正常,启动时旋转myImage15度.现在我只需要创建new Storyboard并将动画添加到其中,因为我需要使用它的Completed事件.我有一点问题,我注意到我可以添加动画Storyboard.Children,但我没有设法定义我要将此动画应用于的对象和属性...
在此先感谢您的帮助,直到现在我才在XAML中创建故事板......
您需要在动画上设置Storyboard附加属性,例如:
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"));
Run Code Online (Sandbox Code Playgroud)
(未经测试;也可以直接定位变换并减少角度路径)