C# 在代码隐藏中将旋转变换动画添加到情节提要
我在代码隐藏中定义了以下动画:C# 在代码隐藏中将旋转变换动画添加到情节提要,c#,wpf,animation,storyboard,C#,Wpf,Animation,Storyboard,我在代码隐藏中定义了以下动画: DoubleAnimation dbAscending = new DoubleAnimation(0, 15, new Duration(TimeSpan.FromMilliseconds(300))); (myImage.RenderTransform as RotateTransform).BeginAnimation(RotateTransform.AngleProperty, dbAscending); 这工作正常,当启动时,它将myImage旋转15
DoubleAnimation dbAscending = new DoubleAnimation(0, 15, new Duration(TimeSpan.FromMilliseconds(300)));
(myImage.RenderTransform as RotateTransform).BeginAnimation(RotateTransform.AngleProperty, dbAscending);
这工作正常,当启动时,它将myImage
旋转15度。现在我只需要创建新的故事板
并将动画添加到其中,因为我需要使用它的完成的
事件。我有一个小问题,我注意到我可以将动画添加到故事板.Children
,但我没有定义要将此动画应用到的对象和属性
提前感谢您的帮助,到目前为止,我只在XAML中创建了情节提要…您需要在动画上设置情节提要附加的属性,例如:
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"));
(未经测试;也可以直接针对变换并减少路径到角度)