public void ScaleEasingAnimation(FrameworkElement element, double from, double to)
 {
     ScaleTransform scale = new ScaleTransform();
     element.RenderTransform = scale;
     element.RenderTransformOrigin = new Point(0.5, 0.5);//定义圆心位置
     DoubleAnimation scaleAnimation = new DoubleAnimation()
     {
         From = from,                                 //起始值
         To = to,                                     //结束值
         //EasingFunction = easing,                    //缓动函数
         Duration = new TimeSpan(0, 0, 0, 0, 200)    //动画播放时间
     };
     AnimationClock clock = scaleAnimation.CreateClock();
     scale.ApplyAnimationClock(ScaleTransform.ScaleXProperty, clock);
     scale.ApplyAnimationClock(ScaleTransform.ScaleYProperty, clock);
 }
Пример #2
0
 public static  void ScaleEasingAnimation(FrameworkElement element)
 {
     ScaleTransform scale = new ScaleTransform();
     element.RenderTransform = scale;
     element.RenderTransformOrigin = new Point(0.5, 0.5);//定义圆心位置
     EasingFunctionBase easing = new ElasticEase()
     {
         EasingMode = EasingMode.EaseOut,            //公式
         Oscillations = 1,                           //滑过动画目标的次数
         Springiness = 10                             //弹簧刚度
     };
     DoubleAnimation scaleAnimation = new DoubleAnimation()
     {
         From = 0,                                 //起始值
         To = 1,                                     //结束值
         EasingFunction = easing,                    //缓动函数
         Duration = new TimeSpan(0, 0, 0, 1, 200)    //动画播放时间
     };
     AnimationClock clock = scaleAnimation.CreateClock();
     scale.ApplyAnimationClock(ScaleTransform.ScaleXProperty, clock);
     scale.ApplyAnimationClock(ScaleTransform.ScaleYProperty, clock);
 }
    private static void ClearScaleTransformAnimation( ScaleTransform transform )
    {
      if( transform == null )
        return;

      // Force a local value before removing the potential animation clock of this transform to avoid leaving the current animated value after animation is removed
      transform.CenterX = 0d;
      transform.ScaleX = 1d;
      transform.ApplyAnimationClock( ScaleTransform.ScaleXProperty, null );
    }
Пример #4
0
 /// <summary>  
 /// 缓动缩放动画 (提升效率)Timeline.DesiredFrameRateProperty.OverrideMetadata(typeof(Timeline), new FrameworkPropertyMetadata { DefaultValue = 20 });  
 /// </summary>  
 /// <param name="element">缩放控件</param>  
 /// <param name="aTime">缩放时间</param>  
 /// <param name="dFrom">缩放起始值(推荐1)</param>  
 /// <param name="dTo">缩放结束值(推荐1.5)</param>  
 /// <param name="aOscillations">滑过动画目标的次数(推荐5)</param>  
 /// <param name="aSpringiness">弹簧刚度(推荐10)</param>  
 /// <returns>返回动画对象</returns>  
 public static AnimationClock ScaleEasingAnimation(FrameworkElement element, TimeSpan aTime, double dFrom, double dTo, int aOscillations, int aSpringiness)
 {
     ScaleTransform scale = new ScaleTransform();
     element.RenderTransform = scale;
     element.RenderTransformOrigin = new Point(0.5, 0.5);//定义圆心位置
     EasingFunctionBase easing = new ElasticEase()
     {
         EasingMode = EasingMode.EaseOut,            //公式
         Oscillations = aOscillations,                           //滑过动画目标的次数
         Springiness = aSpringiness                             //弹簧刚度
     };
     DoubleAnimation scaleAnimation = new DoubleAnimation()
     {
         From = dFrom,                                 //起始值
         To = dTo,                                     //结束值
         EasingFunction = easing,                    //缓动函数
         Duration = aTime    //动画播放时间
     };
     AnimationClock clock = scaleAnimation.CreateClock();
     scale.ApplyAnimationClock(ScaleTransform.ScaleXProperty, clock);
     scale.ApplyAnimationClock(ScaleTransform.ScaleYProperty, clock);
     return clock;
 }