Ejemplo n.º 1
0
 public static void animateHeight(this UIElement element, DependencyProperty prop, double height, int mode)
 {           
     double newHeight;
     ElasticEase cc = new ElasticEase();
     if (mode == 1)
     {
         newHeight = 260;
     }
     else if(mode == 2)
     {
         newHeight = 520;
     }
     else
     {
         newHeight = 0;
     }
     if(height != newHeight)
     {
         DoubleAnimation op = new DoubleAnimation(height, newHeight, program.tSpan);
         
         cc.Springiness = 5;
         cc.Oscillations = 1;
         op.EasingFunction = cc;
         cc.EasingMode = EasingMode.EaseInOut;
         element.BeginAnimation(prop, op);
     }
     
 }
Ejemplo n.º 2
0
        static void OnTargetValuePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            // get animated gauge
            var ag = (AnimatedGauge)d;

            // create animation
            var da = new DoubleAnimation();
            da.To = (double)e.NewValue;
            da.Duration = new Duration(TimeSpan.FromMilliseconds(ag.Duration));
            Storyboard.SetTargetProperty(da, new PropertyPath("Value"));
            Storyboard.SetTarget(da, d);

            // apply easing function
            var ef = ag.EasingFunction;
            if (ef == null)
            {
                var ee = new ElasticEase();
                ee.Oscillations = 1;
                ee.Springiness = 3;
                ef = ee;
            }
            da.EasingFunction = ef;

            // play animation
            var sb = new Storyboard();
            sb.Children.Add(da);
            sb.Begin();
        }
Ejemplo n.º 3
0
        private void btn2_1_Click(object sender, RoutedEventArgs e)
        {
            RotateTransform animatedTranslateTransform = new RotateTransform();
              btn2_1.RenderTransform = animatedTranslateTransform;
              RegisterName("animateButton2", animatedTranslateTransform);

              DoubleAnimationUsingKeyFrames translationAnimation = new DoubleAnimationUsingKeyFrames();
              translationAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0))));

              EasingDoubleKeyFrame doubleKeyFrame2 = new EasingDoubleKeyFrame(360, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(10)));

              ElasticEase ease = new ElasticEase();
              ease.Oscillations = 3;
              ease.Springiness = 8;
              ease.EasingMode = EasingMode.EaseOut;

              doubleKeyFrame2.EasingFunction = ease;
              translationAnimation.KeyFrames.Add(doubleKeyFrame2);

              Storyboard.SetTargetName(translationAnimation, "animateButton2");
              Storyboard.SetTargetProperty(translationAnimation, new PropertyPath(RotateTransform.AngleProperty));

              Storyboard strbStoryboard = new Storyboard();
              strbStoryboard.Children.Add(translationAnimation);

              strbStoryboard.Begin(this);
              UnregisterName("animateButton2");
        }
Ejemplo n.º 4
0
        public static EasingFunctionBase GetEasingFunction()
        {
            EasingFunctionBase result = null;
            switch (random.Next(5))
            {
                case 0:
                    result = new BackEase() { EasingMode = EasingMode.EaseInOut, Amplitude = 0.8 };
                    break;
                case 1:
                    result = new BounceEase() { EasingMode = EasingMode.EaseOut, Bounces = 3, Bounciness = 8 };
                    break;
                case 2:
                    result = new CircleEase() { EasingMode = EasingMode.EaseInOut };
                    break;
                case 3:
                    result = new CubicEase() { EasingMode = EasingMode.EaseIn };
                    break;
                case 4:
                    result = new ElasticEase() { EasingMode = EasingMode.EaseOut, Oscillations = 3, Springiness = 4 };
                    break;
                case 5:
                    result = new SineEase() { EasingMode = EasingMode.EaseInOut };
                    break;
                default:
                    result = new BackEase() { EasingMode = EasingMode.EaseInOut, Amplitude = 0.8 };
                    break;
            }

            return result;
        }
Ejemplo n.º 5
0
 public void InitializeComponent()
 {
     if (_contentLoaded)
     {
         return;
     }
     _contentLoaded = true;
     System.Windows.Application.LoadComponent(this, new System.Uri("/pollAp;component/Page1.xaml", System.UriKind.Relative));
     this.LayoutRoot      = ((System.Windows.Controls.Grid)(this.FindName("LayoutRoot")));
     this.ContentPanel    = ((System.Windows.Controls.Grid)(this.FindName("ContentPanel")));
     this.image1          = ((System.Windows.Controls.Image)(this.FindName("image1")));
     this.myStoryboard8   = ((System.Windows.Media.Animation.Storyboard)(this.FindName("myStoryboard8")));
     this.LayoutRoot1     = ((System.Windows.Controls.StackPanel)(this.FindName("LayoutRoot1")));
     this.myStoryboard    = ((System.Windows.Media.Animation.Storyboard)(this.FindName("myStoryboard")));
     this.myElasticEase   = ((System.Windows.Media.Animation.ElasticEase)(this.FindName("myElasticEase")));
     this.myRectangle     = ((System.Windows.Shapes.Rectangle)(this.FindName("myRectangle")));
     this.LayoutRoot2     = ((System.Windows.Controls.StackPanel)(this.FindName("LayoutRoot2")));
     this.myStoryboard1   = ((System.Windows.Media.Animation.Storyboard)(this.FindName("myStoryboard1")));
     this.myElasticEase1  = ((System.Windows.Media.Animation.ElasticEase)(this.FindName("myElasticEase1")));
     this.myRectangle1    = ((System.Windows.Shapes.Rectangle)(this.FindName("myRectangle1")));
     this.LayoutRoot3     = ((System.Windows.Controls.StackPanel)(this.FindName("LayoutRoot3")));
     this.myStoryboard2   = ((System.Windows.Media.Animation.Storyboard)(this.FindName("myStoryboard2")));
     this.myElasticEase2  = ((System.Windows.Media.Animation.ElasticEase)(this.FindName("myElasticEase2")));
     this.myRectangle2    = ((System.Windows.Shapes.Rectangle)(this.FindName("myRectangle2")));
     this.LayoutRoot4     = ((System.Windows.Controls.StackPanel)(this.FindName("LayoutRoot4")));
     this.myStoryboard3   = ((System.Windows.Media.Animation.Storyboard)(this.FindName("myStoryboard3")));
     this.myElasticEase3  = ((System.Windows.Media.Animation.ElasticEase)(this.FindName("myElasticEase3")));
     this.myRectangle3    = ((System.Windows.Shapes.Rectangle)(this.FindName("myRectangle3")));
     this.LayoutRoot5     = ((System.Windows.Controls.StackPanel)(this.FindName("LayoutRoot5")));
     this.myStoryboard4   = ((System.Windows.Media.Animation.Storyboard)(this.FindName("myStoryboard4")));
     this.myElasticEase4  = ((System.Windows.Media.Animation.ElasticEase)(this.FindName("myElasticEase4")));
     this.myRectangle4    = ((System.Windows.Shapes.Rectangle)(this.FindName("myRectangle4")));
     this.LayoutRoot6     = ((System.Windows.Controls.StackPanel)(this.FindName("LayoutRoot6")));
     this.myStoryboard5   = ((System.Windows.Media.Animation.Storyboard)(this.FindName("myStoryboard5")));
     this.myElasticEase5  = ((System.Windows.Media.Animation.ElasticEase)(this.FindName("myElasticEase5")));
     this.myRectangle5    = ((System.Windows.Shapes.Rectangle)(this.FindName("myRectangle5")));
     this.LayoutRoot7     = ((System.Windows.Controls.StackPanel)(this.FindName("LayoutRoot7")));
     this.myStoryboard6   = ((System.Windows.Media.Animation.Storyboard)(this.FindName("myStoryboard6")));
     this.myElasticEase6  = ((System.Windows.Media.Animation.ElasticEase)(this.FindName("myElasticEase6")));
     this.myRectangle6    = ((System.Windows.Shapes.Rectangle)(this.FindName("myRectangle6")));
     this.LayoutRoot8     = ((System.Windows.Controls.StackPanel)(this.FindName("LayoutRoot8")));
     this.myStoryboard7   = ((System.Windows.Media.Animation.Storyboard)(this.FindName("myStoryboard7")));
     this.myElasticEase7  = ((System.Windows.Media.Animation.ElasticEase)(this.FindName("myElasticEase7")));
     this.myRectangle7    = ((System.Windows.Shapes.Rectangle)(this.FindName("myRectangle7")));
     this.LayoutRoot9     = ((System.Windows.Controls.StackPanel)(this.FindName("LayoutRoot9")));
     this.myStoryboard9   = ((System.Windows.Media.Animation.Storyboard)(this.FindName("myStoryboard9")));
     this.myElasticEase9  = ((System.Windows.Media.Animation.ElasticEase)(this.FindName("myElasticEase9")));
     this.myRectangle9    = ((System.Windows.Shapes.Rectangle)(this.FindName("myRectangle9")));
     this.LayoutRoot10    = ((System.Windows.Controls.StackPanel)(this.FindName("LayoutRoot10")));
     this.myStoryboard10  = ((System.Windows.Media.Animation.Storyboard)(this.FindName("myStoryboard10")));
     this.myElasticEase10 = ((System.Windows.Media.Animation.ElasticEase)(this.FindName("myElasticEase10")));
     this.myRectangle10   = ((System.Windows.Shapes.Rectangle)(this.FindName("myRectangle10")));
     this.MyAnimatedTranslateTransform = ((System.Windows.Media.TranslateTransform)(this.FindName("MyAnimatedTranslateTransform")));
 }
Ejemplo n.º 6
0
 private void Label_OnMouseUp(object sender, MouseButtonEventArgs e)
 {
     var animator = new DLAnimator();
     var fromMatrix = Matrix.Identity;
     var toMatrix = new Matrix(2, 2, -2, 2, 40, 40);
     var easing = new ElasticEase();
     animator.Add(new DLMatrixAnimation(fromMatrix, toMatrix, TimeSpan.FromSeconds(4), o =>
         {
             var current = (Matrix) o;
             _matrixTransform.Matrix = current;
             label.Content = current;
         }, easing));
     animator.BeginAnimations();
 }
 private void FullUpdateWindow_Loaded(object sender, RoutedEventArgs e)
 {
     Storyboard sb = new Storyboard();
     DoubleAnimation myDoubleAnimation = new DoubleAnimation();
     myDoubleAnimation.Duration = new Duration(new TimeSpan(10000000));
     sb.Children.Add(myDoubleAnimation);
     sb.Duration = new Duration(new TimeSpan(10000000));
     Storyboard.SetTarget(myDoubleAnimation, this);
     Storyboard.SetTargetProperty(myDoubleAnimation, new PropertyPath("(Window.Top)"));
     myDoubleAnimation.From = this.Height * -1;
     myDoubleAnimation.To = 150;
     ElasticEase myEaseFunction = new ElasticEase();
     myEaseFunction.EasingMode = EasingMode.EaseOut;
     myEaseFunction.Springiness = 10;
     myEaseFunction.Oscillations = 2;
     myDoubleAnimation.EasingFunction = myEaseFunction;
     sb.Begin();
 }
 private void animationMessage(UC_ELEMENT_InformationPanel myMessage)
 {
     Storyboard sb = new Storyboard();
     DoubleAnimation myDoubleAnimation = new DoubleAnimation();
     myDoubleAnimation.Duration = new Duration(new TimeSpan(8000000));
     sb.Children.Add(myDoubleAnimation);
     sb.Duration = new Duration(new TimeSpan(8000000));
     Storyboard.SetTarget(myDoubleAnimation, this.hostInformationPanel);
     Storyboard.SetTargetProperty(myDoubleAnimation, new PropertyPath("Height"));
     myDoubleAnimation.From = 0;
     myDoubleAnimation.To = myMessage.Height;
     ElasticEase myEaseFunction = new ElasticEase();
     myEaseFunction.EasingMode = EasingMode.EaseOut;
     myEaseFunction.Springiness = 10;
     myEaseFunction.Oscillations = 2;
     myDoubleAnimation.EasingFunction = myEaseFunction;
     sb.Begin();
 }
Ejemplo n.º 9
0
        private IEasingFunction ObterFuncaoDaAnimacao()
        {
            EasingFunctionBase funcaoDaAnimacao = null;
            
            switch (FuncaoDaAnimacao.SelectedValue.ToString())
            {
                case "BackEase":
                    funcaoDaAnimacao =  new BackEase();
                    break;
                case "BounceEase":
                    funcaoDaAnimacao = new BounceEase();
                    break;
                case "CircleEase":
                    funcaoDaAnimacao = new CircleEase();
                    break;
                case "CubicEase":
                    funcaoDaAnimacao = new CubicEase();
                    break;
                case "ElasticEase":
                    funcaoDaAnimacao = new ElasticEase();
                    break;
                case "ExponentialEase":
                    funcaoDaAnimacao = new ExponentialEase();
                    break;
                case "PowerEase":
                    funcaoDaAnimacao = new PowerEase();
                    break;
                case "QuadraticEase":
                    funcaoDaAnimacao = new QuadraticEase();
                    break;
                case "QuarticEase":
                    funcaoDaAnimacao = new QuarticEase();
                    break;
                case "QuinticEase":
                    funcaoDaAnimacao = new QuinticEase();
                    break;
                case "SineEase":
                    funcaoDaAnimacao = new SineEase();
                    break;
            }

            funcaoDaAnimacao.EasingMode = ObterModoDaAnimacao();
            return funcaoDaAnimacao;
        }
Ejemplo n.º 10
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);
 }
Ejemplo n.º 11
0
        public TileControl()
        {
            DefaultStyleKey = typeof(TileControl);

            //Projection = new PlaneProjection();
            RenderTransform = new ScaleTransform();
            RenderTransformOrigin = new Point(0.5, 0.5);

            //Storyboard.SetTargetProperty(horizontalAnimation, new PropertyPath("RotationX"));
            //Storyboard.SetTargetProperty(verticalAnimation, new PropertyPath("RotationY"));
            Storyboard.SetTargetProperty(scaleAnimationX, new PropertyPath("RenderTransform.ScaleX"));
            Storyboard.SetTargetProperty(scaleAnimationY, new PropertyPath("RenderTransform.ScaleY"));
            //Storyboard.SetTarget(horizontalAnimation, Projection);
            //Storyboard.SetTarget(verticalAnimation, Projection);
            Storyboard.SetTarget(scaleAnimationX, this);
            Storyboard.SetTarget(scaleAnimationY, this);

            // add cool elastic ease effect
            var ef1 = new ElasticEase();
            ef1.Oscillations = 1;
            ef1.Springiness = SPRINGINESS;
            ef1.EasingMode = EasingMode.EaseOut;
            scaleAnimationX.EasingFunction = ef1;
            scaleAnimationX.Duration = new Duration(TimeSpan.FromMilliseconds(500));

            // add cool elastic ease effect
            var ef2 = new ElasticEase();
            ef2.Oscillations = 1;
            ef2.Springiness = SPRINGINESS;
            ef2.EasingMode = EasingMode.EaseOut;
            scaleAnimationY.EasingFunction = ef2;
            scaleAnimationY.Duration = new Duration(TimeSpan.FromMilliseconds(500));

            //storyboard.Children.Add(horizontalAnimation);
            //storyboard.Children.Add(verticalAnimation);
            storyboard.Children.Add(scaleAnimationX);
            storyboard.Children.Add(scaleAnimationY);
        }
Ejemplo n.º 12
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);
  }
 private void AnimateInMessageInformation(double messageHeight)
 {
     Storyboard sb = new Storyboard();
     DoubleAnimation myDoubleAnimation = new DoubleAnimation();
     myDoubleAnimation.Duration = new Duration(new TimeSpan(8000000));
     sb.Children.Add(myDoubleAnimation);
     sb.Duration = new Duration(new TimeSpan(8000000));
     Storyboard.SetTarget(myDoubleAnimation, this.GrilleMessagesInformations);
     Storyboard.SetTargetProperty(myDoubleAnimation, new PropertyPath("Height"));
     myDoubleAnimation.From = 0;
     myDoubleAnimation.To = messageHeight;
     ElasticEase myEaseFunction = new ElasticEase();
     myEaseFunction.EasingMode = EasingMode.EaseOut;
     myEaseFunction.Springiness = 10;
     myEaseFunction.Oscillations = 2;
     myDoubleAnimation.EasingFunction = myEaseFunction;
     sb.Begin();
 }
 public void EraseMessageInformation()
 {
     Storyboard sb = new Storyboard();
     DoubleAnimation myDoubleAnimation = new DoubleAnimation();
     myDoubleAnimation.Duration = new Duration(new TimeSpan(8000000));
     sb.Children.Add(myDoubleAnimation);
     sb.Duration = new Duration(new TimeSpan(8000000));
     Storyboard.SetTarget(myDoubleAnimation, this.GrilleMessagesInformations);
     Storyboard.SetTargetProperty(myDoubleAnimation, new PropertyPath("Height"));
     myDoubleAnimation.From = this.GrilleMessagesInformations.Height;
     myDoubleAnimation.To = 0;
     ElasticEase myEaseFunction = new ElasticEase();
     myEaseFunction.EasingMode = EasingMode.EaseIn;
     myEaseFunction.Springiness = 10;
     myEaseFunction.Oscillations = 2;
     myDoubleAnimation.EasingFunction = myEaseFunction;
     sb.Begin();
     sb.Completed += EraseAnimationCompleted;
 }
Ejemplo n.º 15
0
        public void Show()
        {
            Grid grid = GetRootGrid();

            if (grid != null)
            {
                DoubleAnimation opacityAnimation = new DoubleAnimation(0.5, new Duration(TimeSpan.FromSeconds(0.1)));

                Storyboard opacityBoard = new Storyboard();
                opacityBoard.Children.Add(opacityAnimation);

                Storyboard.SetTarget(opacityAnimation, maskRectangle);
                Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath("(Opacity)"));

                opacityBoard.Completed += delegate
                {
                    ScaleTransform scaleTransform = new ScaleTransform(0.0, 0.0, Content.Width / 2.0, Content.Height / 2.0);
                    // Content.RenderTransform = scaleTransform;

                    grid.Children.Add(Content);
                    if (grid.RowDefinitions.Count > 0)
                    {
                        Grid.SetRowSpan(Content, grid.RowDefinitions.Count);
                    }
                    if (grid.ColumnDefinitions.Count > 0)
                    {
                        Grid.SetColumnSpan(Content, grid.ColumnDefinitions.Count);
                    }

                    Storyboard scaleBoard = new Storyboard();
                    EasingFunctionBase easing = new ElasticEase()
                    {
                        EasingMode = EasingMode.EaseOut,
                        Oscillations = 1,
                        Springiness = 3,
                    };

                    DoubleAnimation scaleXAnimation = new DoubleAnimation(1.0, TimeSpan.FromSeconds(0.3));
                    scaleXAnimation.EasingFunction = easing;

                    scaleBoard.Children.Add(scaleXAnimation);

                    Storyboard.SetTarget(scaleXAnimation, Content);
                    Storyboard.SetTargetProperty(scaleXAnimation, new PropertyPath("(UIElement.RenderTransform).(ScaleTransform.ScaleX)"));

                    DoubleAnimation scaleYAnimation = new DoubleAnimation(1.0, TimeSpan.FromSeconds(0.3));
                    scaleYAnimation.EasingFunction = easing;
                    scaleBoard.Children.Add(scaleYAnimation);

                    Storyboard.SetTarget(scaleYAnimation, Content);
                    Storyboard.SetTargetProperty(scaleYAnimation, new PropertyPath("(UIElement.RenderTransform).(ScaleTransform.ScaleY)"));

                    scaleBoard.Begin();
                };

                opacityBoard.Begin();

                grid.Children.Add(maskRectangle);
                if (grid.RowDefinitions.Count > 0)
                {
                    Grid.SetRowSpan(maskRectangle, grid.RowDefinitions.Count);
                }
                if (grid.ColumnDefinitions.Count > 0)
                {
                    Grid.SetColumnSpan(maskRectangle, grid.ColumnDefinitions.Count);
                }

            }
        }
Ejemplo n.º 16
0
        private void IsExpandedChanged()
        {
            if (Children.Count != 2) return;

            Debug.Assert(SplitRatio >= 0 && SplitRatio <= 1.0);

            EnsureStoryboardsLoaded();

            _translateStoryboard.Stop();

            if (IsExpanded)
            {
                _translateAnimations[0].From = 0;
                _translateAnimations[0].To = SplitRatio * ActualHeight;

                _translateAnimations[1].From = 0;
                _translateAnimations[1].To = SplitRatio * ActualHeight;

                EasingFunctionBase ease = new ElasticEase() { EasingMode = EasingMode.EaseOut, Oscillations = 3, Springiness = 7 };
                TimeSpan duration = TimeSpan.FromMilliseconds(750);

                _translateAnimations[0].Duration = duration;
                _translateAnimations[0].EasingFunction = ease;
                _translateAnimations[1].Duration = duration;
                _translateAnimations[1].EasingFunction = ease;
            }
            else
            {
                _fullyExpanded = false;
                InvalidateArrange();
                UpdateLayout();

                _translateAnimations[0].From = SplitRatio * ActualHeight;
                _translateAnimations[0].To = 0;

                _translateAnimations[1].From = SplitRatio * ActualHeight;
                _translateAnimations[1].To = 0;

                EasingFunctionBase ease = new ExponentialEase() { EasingMode = EasingMode.EaseOut };
                TimeSpan duration = TimeSpan.FromMilliseconds(150);

                _translateAnimations[0].Duration = duration;
                _translateAnimations[0].EasingFunction = ease;
                _translateAnimations[1].Duration = duration;
                _translateAnimations[1].EasingFunction = ease;
            }

            _translateStoryboard.Begin();
        }
Ejemplo n.º 17
0
        void tb_cityname_Click(object sender, RoutedEventArgs e)
        {
            stackpanel2.Opacity = 1;
            dax = new DoubleAnimation();
            day = new DoubleAnimation();
            da1 = new DoubleAnimation();
            sb1 = new Storyboard();
            dax.From = 1;
            day.From = 1;
            da1.From = 0;
            dax.To = 180;
            day.To = stackpanel2.ActualHeight;
            da1.To = 1;
            dax.Duration = TimeSpan.FromSeconds(0.6);
            day.Duration = TimeSpan.FromSeconds(0.6);
            da1.Duration = TimeSpan.FromSeconds(0.5);
            ElasticEase be = new ElasticEase();
            be.Oscillations = 1;
            dax.EasingFunction = be;

            day.EasingFunction = be;
            Storyboard.SetTarget(dax, stackpanel2);
            Storyboard.SetTargetProperty(dax, new PropertyPath(StackPanel.WidthProperty));
            Storyboard.SetTarget(day, stackpanel2);
            Storyboard.SetTargetProperty(day, new PropertyPath(StackPanel.HeightProperty));
            Storyboard.SetTarget(da1, stackpanel2);
            Storyboard.SetTargetProperty(da1, new PropertyPath(StackPanel.OpacityProperty));
            sb1.Children.Add(dax);
            sb1.Children.Add(day);
            sb1.Children.Add(da1);
            sb1.Begin();
        }
Ejemplo n.º 18
0
        public void show(double targetx, double targety)
        {
            stackpanel.RenderTransform.SetValue(TranslateTransform.XProperty, targetx);
            stackpanel.RenderTransform.SetValue(TranslateTransform.YProperty, targety);
            stackpanel2.RenderTransform.SetValue(TranslateTransform.XProperty, targetx+stackpanel.ActualWidth+2);
            stackpanel2.RenderTransform.SetValue(TranslateTransform.YProperty, targety-30);
            stackpanel.Opacity =1;
            stackpanel2.Opacity = 0;
              //  stackpanel.Background.Opacity = 1;
            isShowing = true;

            dax = new DoubleAnimation();
            day = new DoubleAnimation();
            da1 = new DoubleAnimation();
            sb1 = new Storyboard();
            dax.From = 1;
            day.From = 1;
            da1.From = 0;
            dax.To =180;
            day.To = stackpanel.ActualHeight;
            da1.To = 1;
            dax.Duration = TimeSpan.FromSeconds(0.6);
            day.Duration = TimeSpan.FromSeconds(0.6);
            da1.Duration = TimeSpan.FromSeconds(0.5);
            ElasticEase be = new ElasticEase();
            be.Oscillations = 1;
            dax.EasingFunction = be;

            day.EasingFunction = be;
            Storyboard.SetTarget(dax, stackpanel);
            Storyboard.SetTargetProperty(dax, new PropertyPath(StackPanel.WidthProperty));
            Storyboard.SetTarget(day, stackpanel);
            Storyboard.SetTargetProperty(day, new PropertyPath(StackPanel.HeightProperty));
            Storyboard.SetTarget(da1, stackpanel);
            Storyboard.SetTargetProperty(da1, new PropertyPath(StackPanel.OpacityProperty));
            sb1.Children.Add(dax);
            sb1.Children.Add(day);
            sb1.Children.Add(da1);
            sb1.Begin();
        }
        /// <summary>
        /// 播放指示条动画
        /// </summary>
        /// <param name="Angle"></param>
        void BeginIndicatorValueChangedAnimation(double Angle)
        {
            if (Angle < 5)  // 如果EndAngle小于5度,则直接显示角度值,QuinticEase会造成过冲,EndAngle会变成负值,造成闪动
            {
                /* 如果上一个动画还在执行中,则先停止动画
                 * 否则执行中的动画可能再次更改EndAngle
                 */
                if (animationclock != null && animationclock.CurrentState != ClockState.Stopped)
                    animationclock.Controller.Stop();

                IndicatorBar.EndAngle = Angle;
            }
            else
            {
                animation = new DoubleAnimation();
                animation.Duration = new Duration(TimeSpan.FromMilliseconds(500));
                animation.To = Angle;

                // QuinticEase ease = new QuinticEase();
                ElasticEase ease = new ElasticEase() { Oscillations = 2, Springiness = 5 };
                ease.EasingMode = EasingMode.EaseOut;
                animation.EasingFunction = ease;

                animationclock = animation.CreateClock();
                animationclock.Completed += animationclock_Completed;

                IndicatorBar.ApplyAnimationClock(Arc.EndAngleProperty, animationclock, HandoffBehavior.SnapshotAndReplace);
                animationclock.Controller.Begin();
            }
        }
Ejemplo n.º 20
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;
 }
Ejemplo n.º 21
0
        public static PlotElementAnimation CreateAnimation(AnimationTransform transform, AnimationOrigin origin, Easing easing, bool indexDelay)
        {
            var sb = new Storyboard();
              var duration = new Duration(TimeSpan.FromSeconds(0.5));

              var style = new Style();
              style.TargetType = typeof(PlotElement);
              style.Setters.Add(new Setter(PlotElement.OpacityProperty, 0.0));

              if (transform == AnimationTransform.Scale)
            style.Setters.Add(new Setter(PlotElement.RenderTransformProperty, new ScaleTransform() { ScaleX = 0, ScaleY = 0 }));
              else if (transform == AnimationTransform.Rotation)
            style.Setters.Add(new Setter(PlotElement.RenderTransformProperty, new RotateTransform() { Angle = 180 }));

              var point = new Point(0.5, 0.5);
              switch (origin)
              {
            case AnimationOrigin.Bottom:
              point = new Point(0.5, 2);
              break;
            case AnimationOrigin.Top:
              point = new Point(0.5, -2);
              break;
            case AnimationOrigin.Left:
              point = new Point(-2, 0.5);
              break;
            case AnimationOrigin.Right:
              point = new Point(2, 0.5);
              break;
            case AnimationOrigin.TopLeft:
              point = new Point(2, -2);
              break;
            case AnimationOrigin.TopRight:
              point = new Point(-2, -2);
              break;
            case AnimationOrigin.BottomLeft:
              point = new Point(2, 2);
              break;
            case AnimationOrigin.BottomRight:
              point = new Point(-2, 2);
              break;
            default:
              break;
              }

              style.Setters.Add(new Setter(PlotElement.RenderTransformOriginProperty, point));

              var da = new DoubleAnimation() { From = 0, To = 1, Duration = duration };
              Storyboard.SetTargetProperty(da, new PropertyPath("Opacity"));
              sb.Children.Add(da);

              if (transform == AnimationTransform.Scale)
              {
            var da2 = new DoubleAnimation() { From = 0, To = 1, Duration = duration };
            Storyboard.SetTargetProperty(da2, new PropertyPath("(RenderTransform).ScaleX"));

            var da3 = new DoubleAnimation() { From = 0, To = 1, Duration = duration };
            Storyboard.SetTargetProperty(da3, new PropertyPath("(RenderTransform).ScaleY"));

            sb.Children.Add(da2);
            sb.Children.Add(da3);
              }
              else if (transform == AnimationTransform.Rotation)
              {
            var da2 = new DoubleAnimation() { To = 0, Duration = duration };
            Storyboard.SetTargetProperty(da2, new PropertyPath("(RenderTransform).Angle"));
            sb.Children.Add(da2);
              }

              if (indexDelay)
              {
            foreach (var anim in sb.Children)
              PlotElementAnimation.SetIndexDelay(anim, 0.5);
              }

            #if CLR40
              if (easing != Easing.None)
              {
            IEasingFunction ef = null;

            switch (easing)
            {
              case Easing.BackEase:
            ef = new BackEase(); break;
              case Easing.BounceEase:
            ef = new BounceEase(); break;
              case Easing.CircleEase:
            ef = new CircleEase(); break;
              case Easing.CubicEase:
            ef = new CubicEase(); break;
              case Easing.ElasticEase:
            ef = new ElasticEase(); break;
              case Easing.ExponentialEase:
            ef = new ExponentialEase(); break;
              case Easing.PowerEase:
            ef = new PowerEase(); break;
              case Easing.QuadraticEase:
            ef = new QuadraticEase(); break;
              case Easing.QuarticEase:
            ef = new QuarticEase(); break;
              case Easing.QuinticEase:
            ef = new QuinticEase(); break;
              case Easing.SineEase:
            ef = new SineEase(); break;

              default:
            break;
            }

            foreach (DoubleAnimation anim in sb.Children)
              anim.EasingFunction = ef;
              }
            #endif

              return new PlotElementAnimation() { Storyboard = sb, SymbolStyle = style };
        }