示例#1
0
        public async Task LoadPage(string pageName, bool addToHistory = true)
        {
            if (pages.ContainsKey(pageName))
            {
                if (pages[pageName] != null)
                {
                    if (currentPage != null)
                    {
                        PageTransitionAnimation animation = pages[pageName].animation.GetOpposite();
                        await currentPage.StartAnimation(false, animation);

                        currentPage.OnUnload();
                    }

                    currentPage       = pages[pageName];
                    PageFrame.Content = pages[pageName];

                    if (addToHistory)
                    {
                        if (history.Count >= 5)
                        {
                            history.RemoveAt(history.Count - 1);
                        }

                        history.Insert(0, pageName);
                    }

                    pages[pageName].OnLoad();
                    await pages[pageName].StartAnimation(true);
                }
            }
        }
示例#2
0
 public async Task StartAnimation(bool inwards, PageTransitionAnimation transitionAnimation)
 {
     if (inwards)
     {
         await StartInAnimation(animation);
     }
     else
     {
         await StartOutAnimation(animation);
     }
 }
示例#3
0
        public static PageTransitionAnimation GetOpposite(this PageTransitionAnimation animation)
        {
            switch (animation)
            {
            case PageTransitionAnimation.None:
                return(PageTransitionAnimation.None);

            case PageTransitionAnimation.SlideTop:
                return(PageTransitionAnimation.SlideBottom);

            case PageTransitionAnimation.SlideLeft:
                return(PageTransitionAnimation.SlideRight);

            case PageTransitionAnimation.SlideBottom:
                return(PageTransitionAnimation.SlideTop);

            case PageTransitionAnimation.SlideRight:
                return(PageTransitionAnimation.SlideLeft);

            default:
                return(PageTransitionAnimation.None);
            }
        }
示例#4
0
        private async Task StartInAnimation(PageTransitionAnimation transitionAnimation)
        {
            if (transitionAnimation == PageTransitionAnimation.None)
            {
                return;
            }

            Storyboard sb = new Storyboard();

            Timeline        animation     = null;
            DoubleAnimation fadeAnimation = new DoubleAnimation
            {
                Duration          = new Duration(TimeSpan.FromSeconds(animationDuration)),
                From              = 0,
                To                = 1,
                DecelerationRatio = 0.9f
            };

            switch (transitionAnimation)
            {
            case PageTransitionAnimation.SlideTop:
                animation = new ThicknessAnimation
                {
                    Duration          = new Duration(TimeSpan.FromSeconds(animationDuration)),
                    From              = new Thickness(0, -MainWindow.Instance.Height, 0, MainWindow.Instance.Height),
                    To                = new Thickness(0),
                    DecelerationRatio = 0.9f
                };
                break;

            case PageTransitionAnimation.SlideLeft:
                animation = new ThicknessAnimation
                {
                    Duration          = new Duration(TimeSpan.FromSeconds(animationDuration)),
                    From              = new Thickness(-MainWindow.Instance.Width, 0, MainWindow.Instance.Width, 0),
                    To                = new Thickness(0),
                    DecelerationRatio = 0.9f
                };
                break;

            case PageTransitionAnimation.SlideBottom:
                animation = new ThicknessAnimation
                {
                    Duration          = new Duration(TimeSpan.FromSeconds(animationDuration)),
                    From              = new Thickness(0, MainWindow.Instance.Height, 0, -MainWindow.Instance.Height),
                    To                = new Thickness(0),
                    DecelerationRatio = 0.9f
                };
                break;

            case PageTransitionAnimation.SlideRight:
                animation = new ThicknessAnimation
                {
                    Duration          = new Duration(TimeSpan.FromSeconds(animationDuration)),
                    From              = new Thickness(MainWindow.Instance.Width, 0, -MainWindow.Instance.Width, 0),
                    To                = new Thickness(0),
                    DecelerationRatio = 0.9f
                };
                break;
            }

            if (animation == null)
            {
                return;
            }

            Storyboard.SetTargetProperty(animation, new PropertyPath("Margin"));
            Storyboard.SetTargetProperty(fadeAnimation, new PropertyPath("Opacity"));
            sb.Children.Add(animation);
            sb.Children.Add(fadeAnimation);

            sb.Begin(this);

            await Task.Delay((int)(animationDuration * 1000));
        }