Пример #1
0
        private void AnimateBorder()
        {
            if (_animationRunning) return;

            _animationRunning = true;
            var offset = VisualTreeHelper.GetOffset(_menuBorder);
            var top = offset.Y;

            var menuOffset = VisualTreeHelper.GetOffset(_menus[_currentMenu]);
            var topOffSet = menuOffset.Y;

            var animation = new DoubleAnimationUsingKeyFrames {Duration = new Duration(TimeSpan.FromSeconds(0.5))};
            var easingFunction = new QuarticEase {EasingMode = EasingMode.EaseInOut};
            var startAnimation = new EasingDoubleKeyFrame(_startPoint, KeyTime.FromPercent(0));
            var endAnimation = new EasingDoubleKeyFrame(topOffSet - top, KeyTime.FromPercent(1.0), easingFunction);
            animation.KeyFrames.Add(startAnimation);
            animation.KeyFrames.Add(endAnimation);

            animation.Completed += delegate
            {
                _animationRunning = false;
            };

            var trans = new TranslateTransform();
            _menuBorder.RenderTransform = trans;
            trans.BeginAnimation(TranslateTransform.YProperty, animation);

            _startPoint = topOffSet - top;
        }
Пример #2
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;
        }
Пример #3
0
        private void ArrowDown_MouseDown(object sender, MouseEventArgs e)
        {
            _currentMenu = Math.Abs(_currentMenu + 1);

            var offset = VisualTreeHelper.GetOffset(MenuBorder);
            var top = offset.Y;

            var menuOffset = VisualTreeHelper.GetOffset(_menus[_currentMenu]);
            var topOffSet = menuOffset.Y;

            var animation = new DoubleAnimationUsingKeyFrames { Duration = new Duration(TimeSpan.FromSeconds(1)) };
            var easingFunction = new QuarticEase { EasingMode = EasingMode.EaseInOut };
            var startAnimation = new EasingDoubleKeyFrame(_startPoint, KeyTime.FromPercent(0));
            var endAnimation = new EasingDoubleKeyFrame(topOffSet - top, KeyTime.FromPercent(1.0), easingFunction);
            animation.KeyFrames.Add(startAnimation);
            animation.KeyFrames.Add(endAnimation);

            var trans = new TranslateTransform();
            MenuBorder.RenderTransform = trans;
            trans.BeginAnimation(TranslateTransform.YProperty, animation);

            _startPoint = topOffSet - top;
        }
Пример #4
0
        public AnimatedFrame()
        {
            var transformGroup = new TransformGroup();
            var oldTransformGroup = RenderTransform as TransformGroup;
            if ((null != oldTransformGroup) && (3 <= oldTransformGroup.Children.Count))
            {
                var offsetTransform = oldTransformGroup.Children[0] as TranslateTransform;
                if (null != offsetTransform)
                {
                    transformGroup.Children.Add(offsetTransform);
                }
            }

            // Add custom transforms
            transformGroup.Children.Add(_rotateTransform);
            transformGroup.Children.Add(_translateTransform);

            // Replace existing transform(s)
            RenderTransform = transformGroup;

            // Set up animation
            _progressAnimation.From = 0;
            _progressAnimation.To = 1;
            Storyboard.SetTarget(_progressAnimation, this);
            Storyboard.SetTargetProperty(_progressAnimation, new PropertyPath("Progress"));
            _progressStoryboard.Children.Add(_progressAnimation);

            // Initialize variables
            EasingFunction = new QuarticEase(); // Initialized here to avoid a single shared instance

            // Hook events
            SizeChanged += HandleSizeChanged;
            OrientationChanged += HandleOrientationChanged;
        }
        /// <summary>
        /// Initializes a new instance of the AnimateOrientationChangesFrame class.
        /// </summary>
        public OrientationChangingFrame()
        {
            // Find existing "offset transform" and take it over (if possible) to support SIP raise/lower
            var transformGroup = new TransformGroup();
            var oldTransformGroup = RenderTransform as TransformGroup;
            if ( ( null != oldTransformGroup ) && ( 3 <= oldTransformGroup.Children.Count ) )
            {
                var offsetTransform = oldTransformGroup.Children[0] as TranslateTransform;
                if ( null != offsetTransform )
                {
                    transformGroup.Children.Add( offsetTransform );
                }
            }
            // Add custom transforms
            transformGroup.Children.Add( _rotateTransform );
            transformGroup.Children.Add( _translateTransform );
            // Replace existing transform(s)
            RenderTransform = transformGroup;

            // Set up animation
            _progressAnimation.From = 0;
            _progressAnimation.To = 1;
            Storyboard.SetTarget( _progressAnimation, this );
            Storyboard.SetTargetProperty( _progressAnimation, new PropertyPath( "Progress" ) );
            _progressStoryboard.Children.Add( _progressAnimation );

            // Initialize variables
            EasingFunction = new QuarticEase(); // Initialized here to avoid a single shared instance

            // Hook events
            SizeChanged += new SizeChangedEventHandler( HandleSizeChanged );
            OrientationChanged += new EventHandler<OrientationChangedEventArgs>( HandleOrientationChanged );
        }
        public void InitialiseSlide(Slide slide, TransitionType transitionType)
        {
            if (transitionType == TransitionType.None)
            {
                slide.Render(SlideshowGrid);
                return;
            }

            // fade out
            var duration = TimeSpan.FromMilliseconds(500);
            var fadeOutAnimation = new DoubleAnimation { From = 1.0, To = 0.0, Duration = new Duration(duration) };
            var fadeOUtEasingFunction = new QuarticEase();
            fadeOUtEasingFunction.EasingMode = EasingMode.EaseInOut;
            fadeOutAnimation.EasingFunction = fadeOUtEasingFunction;

            fadeOutAnimation.Completed += (sender, e) =>
            {
                // fade in
                var fadeInAnimation = new DoubleAnimation { From = 0.0, To = 1.0, Duration = new Duration(duration) };
                var fadeInEasingFunction = new QuarticEase();
                fadeInEasingFunction.EasingMode = EasingMode.EaseInOut;
                fadeInAnimation.EasingFunction = fadeInEasingFunction;
                SlideshowGrid.BeginAnimation(UIElement.OpacityProperty, fadeInAnimation);
                slide.Render(SlideshowGrid);
            };

            SlideshowGrid.BeginAnimation(UIElement.OpacityProperty, fadeOutAnimation);
        }
Пример #7
0
        private void ProgressRoundLoaded(object sender, RoutedEventArgs e)
        {
            Storyboard storyBoard = new Storyboard();

            DoubleAnimation animation = new DoubleAnimation();
            animation.From = 0;
            animation.To = 360 * this.Percent / 100;
            animation.Duration = new Duration(TimeSpan.FromSeconds(1));
            QuarticEase easingFunc = new QuarticEase();
            easingFunc.EasingMode = EasingMode.EaseOut;
            animation.EasingFunction = easingFunc;
            storyBoard.Children.Add(animation);
            Storyboard.SetTarget(animation, this.ringSlice);
            Storyboard.SetTargetProperty(animation, new PropertyPath(RingSlice.EndAngleProperty));

            DoubleAnimation percentAnimation = new DoubleAnimation();
            percentAnimation.From = 0;
            percentAnimation.To = this.Percent;
            percentAnimation.Duration = new Duration(TimeSpan.FromSeconds(1));
            QuarticEase percentEasingFunc = new QuarticEase();
            easingFunc.EasingMode = EasingMode.EaseOut;
            percentAnimation.EasingFunction = percentEasingFunc;
            storyBoard.Children.Add(percentAnimation);
            Storyboard.SetTarget(percentAnimation, this);
            Storyboard.SetTargetProperty(percentAnimation, new PropertyPath(ProgressRound.AnimatedPercentProperty));

            storyBoard.Begin();
        }
        /// <summary>
        /// 绘制进度条的圆弧
        /// </summary>
        void DrawAngle()
        {
            double angle = 0.1;
            double percent = 0;

            if (this.Min == this.Max)
            {
                angle = 0.1;
                percent = 0;
            }
            else
            {
                angle = (this.Progress - this.Min) / (this.Max - this.Min) * 360; // 计算圆弧绘制的弧度
                if (angle <= 0)
                    angle = 0.1;

                percent = (this.Progress - this.Min) / (this.Max - this.Min) * 100;  // 计算百分比
                if (percent <= 0)
                    percent = 0;
            }

            // 绘制圆弧用到的动画
            QuarticEase ease = new QuarticEase() { EasingMode = EasingMode.EaseOut };
            DoubleAnimation animation = new DoubleAnimation();
            animation.Duration = new Duration(TimeSpan.FromMilliseconds(500));
            animation.To = angle;
            animation.EasingFunction = ease;
            animationclock = animation.CreateClock();
            animationclock.Completed += animationclock_Completed;

            // 绘制圆弧
            this.ProgressIndicator.ApplyAnimationClock(Arc.EndAngleProperty, animationclock, HandoffBehavior.SnapshotAndReplace);
            this.txt_ProgressValue.Text = string.Format("{0}%", percent.ToString("F1"));
        }
Пример #9
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 };
        }
Пример #10
0
        public static void TransitionAnimation(Thickness movefrom, Thickness moveTarget, MobileItem MoveItem,Storyboard transitionStoryboard = null, double begintime = 0, double duration = 1)
        {
            ThicknessAnimation movegrid = new ThicknessAnimation()
            {
                From = movefrom,
                To = moveTarget,
                BeginTime = TimeSpan.FromSeconds(begintime),
                Duration = TimeSpan.FromSeconds(duration)
            };
            QuarticEase be = new QuarticEase();
            movegrid.EasingFunction = be;

            Storyboard.SetTarget(movegrid, MoveItem);
            Storyboard.SetTargetProperty(movegrid, new PropertyPath(Grid.MarginProperty));

            //Storyboard sb = new Storyboard();

            EventHandler handler = null;
            handler = delegate
            {
                transitionStoryboard.Completed -= handler;
                transitionStoryboard.Stop();
                MoveItem.Margin = moveTarget;
                //Console.WriteLine(MoveItem.MobileSpecification.NAME + " Margin : " + MoveItem.Margin);

            };
            transitionStoryboard.Children.Add(movegrid);
            transitionStoryboard.Completed += handler;
            //sb.Begin();
        }
Пример #11
0
 static Animation()
 {
     TypicalDuration = TimeSpan.FromMilliseconds((double)AnimationSpeed.Normal);
     TypicalEasing = new QuarticEase { EasingMode = EasingMode.EaseOut };
     TypicalEasing.Freeze();
 }