DoubleAnimation反转速度提高2倍

时间:2014-09-08 07:05:27

标签: c# animation storyboard

我为DoubleAnimation设置DropShadowEffect来更改Blur Radius上下生成一个发光的动画阴影:

DropShadowEffect DS = new DropShadowEffect();

                /// Whatever DS settings here

                Target.Effect = DS;

                DoubleAnimation DSr = new DoubleAnimation(0, 25, new Duration(TimeSpan.FromMilliseconds(500)));
                DSr.AutoReverse = true;
                DSr.RepeatBehavior = RepeatBehavior.Forever;

                DS.BeginAnimation(DropShadowEffect.BlurRadiusProperty, DSr);

向前迈出一步需要20毫秒,总时间为500毫秒。

是否可以每10毫秒执行一次反向操作,总时间为250毫秒(正常速度的两倍)。

1 个答案:

答案 0 :(得分:1)

我想我可以使用Completed事件做这样的事情:

DoubleAnimation animation = new DoubleAnimation(0.0, 1.0);

animation.Duration = TimeSpan.FromMilliseconds(500);

animation.Completed += (s, e) =>
        {
            If (target.opacity == 1)
            {
                animation.From = 1.0;
                animation.To = 0.0;
                animation.Duration = TimeSpan.FromMilliseconds(250);

                element.BeginAnimation(OpacityProperty, animation);
            }
            else
            {
                animation.From = 0.0;
                animation.To = 1.0;
                animation.SpeedRatio = TimeSpan.FromMilliseconds(500);

                element.BeginAnimation(OpacityProperty, animation);
            }
        }

element.BeginAnimation(OpacityProperty, animation);