关键帧动画

Storyboard storyboard = new Storyboard();

        Storyboard sb = new Storyboard();

//播放按钮,创建关键帧动画 和线性动画

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            //DoubleAnimationUsingKeyFrames daanimation = new DoubleAnimationUsingKeyFrames();
            //Storyboard.SetTarget(daanimation, ellipse1);
            //Storyboard.SetTargetProperty(daanimation, new PropertyPath("(Canvas.Top)"));
            //daanimation.Duration = TimeSpan.FromSeconds(40);


            //LinearDoubleKeyFrame linearDoubleKeyFrame = new LinearDoubleKeyFrame(200, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(10)));
            //daanimation.KeyFrames.Add(linearDoubleKeyFrame);
            //daanimation.KeyFrames.Add(new DiscreteDoubleKeyFrame(300, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(15))));
            //daanimation.KeyFrames.Add(new SplineDoubleKeyFrame(600, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(20)),
            //           new KeySpline(new Point(0, 1), new Point(1, 0))));
            //Storyboard sb = new Storyboard();
            //sb.Children.Add(daanimation);
            //sb.Begin(ellipse1, true);
            //sb.SetSpeedRatio(ellipse1, 4);




            //2.创建关键帧动画
            DoubleAnimationUsingKeyFrames doubleAnimationUsingKeyFrames = new DoubleAnimationUsingKeyFrames();




            storyboard.Children.Add(doubleAnimationUsingKeyFrames);//把动画添加到故事板
            Storyboard.SetTarget(doubleAnimationUsingKeyFrames, ellipse1);//设置Target
            Storyboard.SetTargetProperty(doubleAnimationUsingKeyFrames, new PropertyPath(Ellipse.ForceCursorProperty));//设置TargetProperty
            doubleAnimationUsingKeyFrames.Duration = new Duration(TimeSpan.FromSeconds(40));


            //3.创建关键帧 并添加到KeyFrames 中  这里创建了3个样条关键帧
            LinearDoubleKeyFrame linearDoubleKeyFrame=null; 
            int[] sd=new int[3]{200,300,350};
            int[] ti = new int[3] { 20,25,40};
            
            for (int i = 0; i <= 2; i++)
            {
                linearDoubleKeyFrame = new LinearDoubleKeyFrame(sd[i], KeyTime.FromTimeSpan(TimeSpan.FromSeconds(ti[i])));
            }
            doubleAnimationUsingKeyFrames.KeyFrames.Add(linearDoubleKeyFrame);
            //doubleAnimationUsingKeyFrames.KeyFrames.Add(new DiscreteDoubleKeyFrame(300, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(15))));
            //doubleAnimationUsingKeyFrames.KeyFrames.Add(new SplineDoubleKeyFrame(600, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(20)),
                      // new KeySpline(new Point(0, 1), new Point(1, 0))));




       


            DoubleAnimation daanimation = new DoubleAnimation();
            daanimation.From = 0;
            daanimation.To = 1;
            daanimation.Duration = TimeSpan.FromSeconds(40);
            Storyboard.SetTarget(daanimation, myslider);
            Storyboard.SetTargetProperty(daanimation, new PropertyPath(Slider.ValueProperty));
            sb.Children.Add(daanimation);
            sb.Begin(myslider, true);
            storyboard.Begin(ellipse1, true);
            storyboard.SetSpeedRatio(ellipse1, 4);
            sb.SetSpeedRatio(myslider, 4);
        }

//控制进度条进度和当前时间
        private void myslider_ValueChanged_1(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            double? d = sb.GetCurrentProgress(myslider);
            this.myslider.Value = Convert.ToDouble(d);


            TimeSpan? tm = sb.GetCurrentTime(myslider);
            string r = Regex.Replace(tm.ToString(), @"\.\d+$", string.Empty);
            this.mytext.Text = r;
            //dds();
        }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值