DoubleAnimation反转速度快2倍

本文关键字:2倍 速度快 DoubleAnimation | 更新日期: 2023-09-27 18:20:56

我为DropShadowEffect设置了一个DoubleAnimation,以上下更改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毫秒(正常速度的两倍)。

DoubleAnimation反转速度快2倍

我想我可以使用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);