예제 #1
0
        public static Storyboard CreateHeartBeatAnimation(AnimationRequest request, TimeSpan interval, TimeSpan duration)
        {
            var transform = new CompositeTransform();

            request.Target.RenderTransform       = transform;
            request.Target.RenderTransformOrigin = new Point(0.5, 0.5);

            var sb = new Storyboard()
            {
                Duration = interval, RepeatBehavior = RepeatBehavior.Forever
            };

            var sday = new DoubleAnimation {
                Duration = duration, AutoReverse = true, EasingFunction = new BounceEase(), From = 1.0, To = 1.5
            };

            Storyboard.SetTarget(sday, transform);
            Storyboard.SetTargetProperty(sday, nameof(CompositeTransform.ScaleY));
            sb.Children.Add(sday);

            var sdax = new DoubleAnimation {
                Duration = duration, AutoReverse = true, EasingFunction = new BounceEase(), From = 1.0, To = 1.5
            };

            Storyboard.SetTarget(sdax, transform);
            Storyboard.SetTargetProperty(sdax, nameof(CompositeTransform.ScaleX));
            sb.Children.Add(sdax);

            return(sb);
        }
예제 #2
0
        public static Storyboard CreateRotateAnimation(AnimationRequest request, double from, double to)
        {
            var duration = new Duration(TimeSpan.FromMilliseconds(200));

            if (request.Duration != null && request.Duration.Milliseconds != 0)
            {
                duration = request.Duration;
            }

            var sb = new Storyboard()
            {
                Duration = duration
            };
            var da = new DoubleAnimation()
            {
                Duration = duration
            };

            sb.Children.Add(da);

            var rt = new RotateTransform();

            Storyboard.SetTarget(da, rt);
            Storyboard.SetTargetProperty(da, nameof(RotateTransform.Angle));
            da.From = from;
            da.To   = to;

            request.Target.RenderTransform       = rt;
            request.Target.RenderTransformOrigin = new Point(0.5, 0.5);

            return(sb);
        }
예제 #3
0
        /// <summary>
        /// Create a storyboard with an animation to change angle and scale
        /// </summary>
        /// <param name="request">A object that includes target UIElement</param>
        /// <param name="angle">relative angle to rotate. e.g.: -90</param>
        /// <param name="scale">absolute scale. e.g.: 1.5</param>
        /// <returns></returns>
        public static Storyboard CreateSmoothRotateScaleAnimation(AnimationRequest request, double angle, double scale)
        {
            var transform = request.Target.RenderTransform as CompositeTransform;

            if (transform == null)
            {
                transform = new CompositeTransform()
                {
                    ScaleX   = 1.0,
                    ScaleY   = 1.0,
                    Rotation = 0,
                };
                request.Target.RenderTransform = transform;
            }

            transform.CenterX = request.Target.RenderSize.Width / 2;
            transform.CenterY = request.Target.RenderSize.Height / 2;

            var duration = new Duration(TimeSpan.FromMilliseconds(200));

            if (request.Duration != null && request.Duration.Milliseconds != 0)
            {
                duration = request.Duration;
            }

            var sb = new Storyboard()
            {
                Duration = duration
            };

            var animation = _Animation(duration, transform.Rotation, angle);

            Storyboard.SetTargetProperty(animation, nameof(CompositeTransform.Rotation));
            Storyboard.SetTarget(animation, transform);
            sb.Children.Add(animation);

            var scaleXAnimation = _Animation(duration, transform.ScaleX, scale - transform.ScaleX);

            Storyboard.SetTargetProperty(scaleXAnimation, nameof(CompositeTransform.ScaleX));
            Storyboard.SetTarget(scaleXAnimation, transform);
            sb.Children.Add(scaleXAnimation);

            var scaleYAnimation = _Animation(duration, transform.ScaleY, scale - transform.ScaleY);

            Storyboard.SetTargetProperty(scaleYAnimation, nameof(CompositeTransform.ScaleY));
            Storyboard.SetTarget(scaleYAnimation, transform);
            sb.Children.Add(scaleYAnimation);

            if (request.Completed != null)
            {
                sb.Completed += request.Completed;
            }
            return(sb);
        }
예제 #4
0
        public static Storyboard CreateSmoothRotateAnimation(AnimationRequest request, double angle)
        {
            if (double.IsNaN(angle))
            {
                angle = 0;
            }
            var transform = request.Target.RenderTransform as CompositeTransform;

            if (transform == null)
            {
                transform = new CompositeTransform()
                {
                    Rotation = 0,
                };
                request.Target.RenderTransform = transform;
            }

            var duration = new Duration(TimeSpan.FromMilliseconds(200));

            if (request.Duration != null && request.Duration.Milliseconds != 0)
            {
                duration = request.Duration;
            }

            var sb = new Storyboard()
            {
                Duration = duration
            };

            var animation = _Animation(duration, transform.Rotation, angle);

            Storyboard.SetTargetProperty(animation, nameof(CompositeTransform.Rotation));
            Storyboard.SetTarget(animation, transform);

            sb.Children.Add(animation);

            if (request.Completed != null)
            {
                sb.Completed += request.Completed;
            }

            return(sb);
        }