原文:
先说明思路:一个故事版Storyboard,两个双精度动画帧DoubleAnimation。
一个一个执行的原理:控制动画开始时间(例如第一个动画用时2秒,第二个动画就第2秒起开始执行。)
XAML:
后台代码:
#region 创建故事版 //创建一个故事版 Storyboard storyboard = new Storyboard(); private void CreateStoryboard() { //定义动画1运行时间==动画2等待时间 TimeSpan ts = new TimeSpan(0, 0, 1); #region 创建第一个动画 DoubleAnimation doubleAnimation = new DoubleAnimation(); //目标角度 doubleAnimation.To = 360; //结束时间 doubleAnimation.Duration = new Duration(ts); Storyboard.SetTarget(doubleAnimation, img_FanRotate); Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)")); storyboard.Children.Add(doubleAnimation); #endregion #region 创建第二个动画 DoubleAnimation doubleAnimation2 = new DoubleAnimation(); //目标角度 doubleAnimation2.To = 360; //设置等待时间 doubleAnimation2.BeginTime = ts; //结束时间 doubleAnimation2.Duration = new Duration(new TimeSpan(0, 0, 1)); //故事版中设置目标 Storyboard.SetTarget(doubleAnimation2, img_FanRotate2); //故事版中设置属性路径 Storyboard.SetTargetProperty(doubleAnimation2, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)")); //将动画添加至故事版末尾 storyboard.Children.Add(doubleAnimation2); #endregion //开始故事版 //storyboard.Begin(); } #endregion
#region 按钮 //开始 private void button3_Click(object sender, RoutedEventArgs e) { storyboard.Begin(img_FanRotate, true); storyboard.Begin(img_FanRotate2, true); } //暂停 private void button_Click(object sender, RoutedEventArgs e) { storyboard.Pause(img_FanRotate); storyboard.Pause(img_FanRotate2); } //继续 private void button1_Click(object sender, RoutedEventArgs e) { storyboard.Resume(img_FanRotate); storyboard.Resume(img_FanRotate2); } //停止 private void button2_Click(object sender, RoutedEventArgs e) { storyboard.Stop(img_FanRotate); storyboard.Stop(img_FanRotate2); } #endregion
posted on 2018-08-30 11:53 阅读( ...) 评论( ...)