예제 #1
0
        private void button4_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            //定义多关键帧动画
            DoubleAnimationUsingKeyFrames daukf = new DoubleAnimationUsingKeyFrames();

            sb4 = new Storyboard();
            this.sb4.Completed    += new System.EventHandler(Storyboard_Completed);
            this.button1.IsEnabled = false;
            this.button2.IsEnabled = false;
            this.button3.IsEnabled = false;
            this.button4.IsEnabled = false;
            sb4.Children.Add(daukf);
            //动画影响属性:元素的三维旋转(以Y轴为旋转轴)
            Storyboard.SetTargetProperty(daukf, new PropertyPath("(UIElement.Projection).(PlaneProjection.RotationY)"));
            Storyboard.SetTarget(daukf, image);
            //定义第1个可插入的关键帧(可以和Silverlight目前提供的11种缓动函数关联)
            //(缓动函数设置了关键帧之间的动画过渡状态)
            EasingDoubleKeyFrame kf1 = new EasingDoubleKeyFrame();

            kf1.Value   = 80;                       //设置此关键帧的目标值(旋转度数)
            kf1.KeyTime = new TimeSpan(0, 0, 0, 3); //设置达到目标值的时间(日,小时,分,秒)
            BackEase kf1be = new BackEase();        //定义具有收回效果的缓动函数对象

            //EasingMode有3种选择:EaseIn、EaseOut和EaseInOut
            kf1be.EasingMode   = EasingMode.EaseOut; //EaseOut方式
            kf1.EasingFunction = kf1be;              //第1帧使用缓动函数BackEase的EaseOut方式过渡
            //定义第2个可插入的关键帧
            EasingDoubleKeyFrame kf2 = new EasingDoubleKeyFrame();

            kf2.Value   = 0;
            kf2.KeyTime = new TimeSpan(0, 0, 0, 6); //第2帧达到第6秒
            BounceEase kf2be = new BounceEase();    //定义具有反弹效果的缓动函数对象

            kf2be.EasingMode   = EasingMode.EaseIn; //EaseIn方式
            kf2be.Bounces      = 3;                 //反弹3次
            kf2.EasingFunction = kf2be;             //第2帧使用缓动函数BounceEase的EaseIn方式过渡
            //定义第3个可插入的关键帧
            EasingDoubleKeyFrame kf3 = new EasingDoubleKeyFrame();

            kf3.Value   = -80;
            kf3.KeyTime = new TimeSpan(0, 0, 0, 9);    //第3帧达到第9秒
            ElasticEase kf3ee = new ElasticEase();     //定义具有衰减振荡效果的缓动函数对象

            kf3ee.EasingMode   = EasingMode.EaseInOut; //EaseInOut方式
            kf3ee.Oscillations = 4;                    //振荡次数
            kf3ee.Ease(4);                             //衰减振荡持续时间
            kf3.EasingFunction = kf3ee;                //第3帧使用缓动函数ElasticEase的EaseInOut方式过渡
            //定义第4个可插入的关键帧
            EasingDoubleKeyFrame kf4 = new EasingDoubleKeyFrame();

            kf4.Value   = 0;
            kf4.KeyTime = new TimeSpan(0, 0, 0, 12); //第4帧达到第12秒
            daukf.KeyFrames.Add(kf1);                //添加关键帧
            daukf.KeyFrames.Add(kf2);
            daukf.KeyFrames.Add(kf3);
            daukf.KeyFrames.Add(kf4);
            daukf.AutoReverse    = true;                  //允许翻转
            daukf.RepeatBehavior = new RepeatBehavior(1); //反复1次
            sb4.Begin();
        }
예제 #2
0
    /// <summary>
    /// Animates the grid let set
    /// </summary>
    /// <param name="defaultOriginValue">The original value to animate</param>
    /// <param name="defaultDestinationValue">The final value</param>
    /// <param name="animationClock">The animation clock (timer)</param>
    /// <returns>Returns the new grid length to set</returns>
    public override object GetCurrentValue(object defaultOriginValue,
                                           object defaultDestinationValue, AnimationClock animationClock)
    {
        //check the animation clock event
        VerifyAnimationCompletedStatus(animationClock);

        //check if the animation was completed
        if (_isCompleted)
        {
            return((GridLength)defaultDestinationValue);
        }

        //if not then create the value to animate
        var fromVal = From.Value;
        var toVal   = To.Value;

        //check if the value is already collapsed
        if (Math.Abs(((GridLength)defaultOriginValue).Value - toVal) < 0.1)
        {
            fromVal = toVal;
            toVal   = ReverseValue;
        }
        else
        //check to see if this is the last tick of the animation clock.
        {
            Debug.Assert(animationClock.CurrentProgress != null, "animationClock.CurrentProgress != null");
            if (Math.Abs(animationClock.CurrentProgress.Value - 1.0) < 0.1)
            {
                return(To);
            }
        }

        EasingFunctionBase easing = new ElasticEase {
            Oscillations = 2, EasingMode = EasingMode.EaseOut, Springiness = 10
        };

        Debug.Assert(animationClock.CurrentProgress != null, "animationClock.CurrentProgress != null");

        if (fromVal > toVal)
        {
            return(new GridLength((1 - easing.Ease(animationClock.CurrentProgress.Value)) * (fromVal - toVal) + toVal,
                                  From.IsStar ? GridUnitType.Star : GridUnitType.Pixel));
        }
        return(new GridLength(easing.Ease(animationClock.CurrentProgress.Value) * (toVal - fromVal) + fromVal,
                              From.IsStar ? GridUnitType.Star : GridUnitType.Pixel));
    }
예제 #3
0
    /// <summary>
    /// Animates the grid let set
    /// </summary>
    /// <param name=”defaultOriginValue”>The original value to animate</param>
    /// <param name=”defaultDestinationValue”>The final value</param>
    /// <param name=”animationClock”>The animation clock (timer)</param>
    /// <returns>Returns the new grid length to set</returns>
    public override object GetCurrentValue(object defaultOriginValue,
                                           object defaultDestinationValue, AnimationClock animationClock)
    {
        //check the animation clock event
        VerifyAnimationCompletedStatus(animationClock);

        //check if the animation was completed
        if (isCompleted)
        {
            return((GridLength)defaultDestinationValue);
        }

        //if not then create the value to animate
        double fromVal = this.From.Value;
        double toVal   = this.To.Value;

        //check if the value is already collapsed
        if (((GridLength)defaultOriginValue).Value == toVal)
        {
            fromVal = toVal;
            toVal   = this.ReverseValue;
        }
        else
        //check to see if this is the last tick of the animation clock.
        if (animationClock.CurrentProgress.Value == 1.0)
        {
            return(To);
        }

        EasingFunctionBase easing = new ElasticEase()
        {
            Oscillations = 2, EasingMode = EasingMode.EaseOut, Springiness = 10
        };

        if (fromVal > toVal)
        {
            return(new GridLength((1 - easing.Ease(animationClock.CurrentProgress.Value)) * (fromVal - toVal) + toVal,
                                  this.From.IsStar ? GridUnitType.Star : GridUnitType.Pixel));
        }
        else
        {
            return(new GridLength(easing.Ease(animationClock.CurrentProgress.Value) * (toVal - fromVal) + fromVal,
                                  this.From.IsStar ? GridUnitType.Star : GridUnitType.Pixel));
        }
    }