Ejemplo n.º 1
0
        private static DoubleAnimation CreateAnimation(ViewFrame viewFrame, PageTransitionDirection direction)
        {
            var transitionTarget = viewFrame;

            // 初始化 Effect
            var effect = new TransitionSlideInEffect
            {
                Texture2 = new ImageBrush(TakeSnap(transitionTarget)),
                Progress = 0
            };

            switch (direction)
            {
            case PageTransitionDirection.LeftToRight:
                effect.SlideAmount = new Point(-1.0, 0.0);
                break;

            case PageTransitionDirection.RightToLeft:
                effect.SlideAmount = new Point(1.0, 0.0);
                break;

            case PageTransitionDirection.TopToBottom:
                effect.SlideAmount = new Point(0.0, -1.0);
                break;

            case PageTransitionDirection.BottomToTop:
                effect.SlideAmount = new Point(0.0, 1.0);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(direction), direction, null);
            }

            transitionTarget.Effect = effect;

            var doubleAnimation = new DoubleAnimation(0, 100, TimeSpan.FromMilliseconds(300))
            {
                EasingFunction = new PowerEase()
                {
                    EasingMode = EasingMode.EaseOut
                }
            };

            doubleAnimation.Completed += (sender, args) =>
            {
                transitionTarget.Effect = null;
            };

            return(doubleAnimation);
        }
Ejemplo n.º 2
0
        public static DoubleAnimation CheckOutAnimation([NotNull] this ViewFrame viewFrame, [CanBeNull] UIElement target)
        {
            if (viewFrame == null)
            {
                throw new ArgumentNullException(nameof(viewFrame));
            }

            // 如果 target 无法转换为 IPageTransitionAnimation,则表示其没有实现这个接口,返回空
            // ReSharper disable once SuspiciousTypeConversion.Global
            if (!(target is IPageTransitionAnimation animation))
            {
                return(null);
            }

            if (animation.InOutMode == PageTransitionMode.OnlyIn)
            {
                return(null);
            }

            return(CreateAnimation(viewFrame, animation.OutDirection));
        }