Esempio n. 1
0
        /// <summary>
        /// Animates the offset of the the UIElement.
        /// </summary>
        /// <param name="animationSet">The animation set.</param>
        /// <param name="offsetX">The offset on the x axis.</param>
        /// <param name="offsetY">The offset on the y axis.</param>
        /// <param name="duration">The duration in milliseconds.</param>
        /// <param name="delay">The delay in milliseconds. (ignored if duration == 0)</param>
        /// <param name="easingType">Used to describe how the animation interpolates between keyframes.</param>
        /// <returns>
        /// An AnimationSet.
        /// </returns>
        public static AnimationSet Offset(
            this AnimationSet animationSet,
            float offsetX         = 0f,
            float offsetY         = 0f,
            double duration       = 500d,
            double delay          = 0d,
            EasingType easingType = EasingType.Default)
        {
            if (animationSet == null)
            {
                return(null);
            }

            if (!AnimationSet.UseComposition)
            {
                var element   = animationSet.Element;
                var transform = GetAttachedCompositeTransform(element);

                var animationX = new DoubleAnimation();
                var animationY = new DoubleAnimation();

                animationX.To = offsetX;
                animationY.To = offsetY;

                animationX.Duration       = animationY.Duration = TimeSpan.FromMilliseconds(duration);
                animationX.BeginTime      = animationY.BeginTime = TimeSpan.FromMilliseconds(delay);
                animationX.EasingFunction = animationY.EasingFunction = GetEasingFunction(easingType);

                animationSet.AddStoryboardAnimation(GetAnimationPath(transform, element, "TranslateX"), animationX);
                animationSet.AddStoryboardAnimation(GetAnimationPath(transform, element, "TranslateY"), animationY);
            }
            else
            {
                var visual       = animationSet.Visual;
                var offsetVector = new Vector3(offsetX, offsetY, 0);

                if (duration <= 0)
                {
                    animationSet.AddCompositionDirectPropertyChange("Offset", offsetVector);
                    return(animationSet);
                }

                var compositor = visual?.Compositor;

                if (compositor == null)
                {
                    return(null);
                }

                var animation = compositor.CreateVector3KeyFrameAnimation();
                animation.Duration  = TimeSpan.FromMilliseconds(duration);
                animation.DelayTime = TimeSpan.FromMilliseconds(delay);
                animation.InsertKeyFrame(1f, offsetVector);

                animationSet.AddCompositionAnimation("Offset", animation);
            }

            return(animationSet);
        }
Esempio n. 2
0
        public static AnimationSet Scale(
            this AnimationSet animationSet,
            float scaleX    = 1f,
            float scaleY    = 1f,
            float centerX   = 0f,
            float centerY   = 0f,
            double duration = 500d,
            double delay    = 0d)
        {
            if (animationSet == null)
            {
                return(null);
            }

            if (!AnimationSet.UseComposition)
            {
                var element   = animationSet.Element;
                var transform = GetAttachedCompositeTransform(element);

                transform.CenterX = centerX;
                transform.CenterY = centerY;

                var animationX = new DoubleAnimation();
                var animationY = new DoubleAnimation();

                animationX.To = scaleX;
                animationY.To = scaleY;

                animationX.Duration       = animationY.Duration = TimeSpan.FromMilliseconds(duration);
                animationX.BeginTime      = animationY.BeginTime = TimeSpan.FromMilliseconds(delay);
                animationX.EasingFunction = animationY.EasingFunction = _defaultStoryboardEasingFunction;

                animationSet.AddStoryboardAnimation(GetAnimationPath(transform, element, "ScaleX"), animationX);
                animationSet.AddStoryboardAnimation(GetAnimationPath(transform, element, "ScaleY"), animationY);
            }
            else
            {
                var visual = animationSet.Visual;
                visual.CenterPoint = new Vector3(centerX, centerY, 0);
                var scaleVector = new Vector3(scaleX, scaleY, 1.0f);

                if (duration <= 0)
                {
                    animationSet.AddCompositionDirectPropertyChange("Scale", scaleVector);
                    return(animationSet);
                }

                var compositor = visual.Compositor;

                if (compositor == null)
                {
                    return(null);
                }

                var animation = compositor.CreateVector3KeyFrameAnimation();
                animation.Duration  = TimeSpan.FromMilliseconds(duration);
                animation.DelayTime = TimeSpan.FromMilliseconds(delay);
                animation.InsertKeyFrame(1f, scaleVector);

                animationSet.AddCompositionAnimation("Scale", animation);
            }

            return(animationSet);
        }