Ejemplo n.º 1
0
        public virtual void ShowCarouselPage(
            Type view,
            MvxCarouselPagePresentationAttribute attribute,
            MvxViewModelRequest request)
        {
            var page = CloseAndCreatePage(view, request, attribute);

            if (attribute.Position == CarouselPosition.Root)
            {
                if (!(page is MvxCarouselPage carouselPageRoot))
                {
                    throw new MvxException($"A root page should be of type {nameof(MvxCarouselPage)}");
                }

                PushOrReplacePage(FormsApplication.MainPage, page, attribute);
            }
            else
            {
                var carouselHost = GetHostPageOfType <MvxCarouselPage>();
                if (carouselHost == null)
                {
                    MvxTrace.Trace($"Current root is not a CarouselPage show your own first to use custom Host. Assuming we need to create one.");
                    carouselHost = new MvxCarouselPage();
                    PushOrReplacePage(FormsApplication.MainPage, carouselHost, attribute);
                }
                carouselHost.Children.Add(page as ContentPage);
            }
        }
Ejemplo n.º 2
0
        public virtual void ShowCarouselPage(
            Type view,
            MvxCarouselPagePresentationAttribute attribute,
            MvxViewModelRequest request)
        {
            CloseAllModals();

            var page = CreatePage(view, request);

            if (attribute.Position == CarouselPosition.Root)
            {
                if (page is CarouselPage carouselPageRoot)
                {
                    if (attribute.WrapInNavigationPage && FormsApplication.MainPage is MvxNavigationPage currentPage)
                    {
                        currentPage.PushAsync(page);
                    }
                    else if (attribute.WrapInNavigationPage)
                    {
                        FormsApplication.MainPage = new MvxNavigationPage(page);
                    }
                    else
                    {
                        FormsApplication.MainPage = page;
                    }
                }
                else
                {
                    throw new MvxException($"A root page should be of type {nameof(CarouselPage)}");
                }
            }
            else
            {
                var carouselHost = FormsApplication.MainPage as CarouselPage;
                if (carouselHost == null && FormsApplication.MainPage is MvxNavigationPage navigationPage)
                {
                    carouselHost = navigationPage.CurrentPage as CarouselPage;
                    if (carouselHost == null)
                    {
                        MvxTrace.Trace($"Current root is not a CarouselPage show your own first to use custom Host. Assuming we need to create one.");
                        carouselHost = new MvxCarouselPage();
                        navigationPage.PushAsync(carouselHost);
                    }
                }
                else if (carouselHost == null)
                {
                    MvxTrace.Trace($"Current root is not a CarouselPage show your own first to use custom Host. Assuming we need to create one.");
                    carouselHost = new MvxCarouselPage();
                    FormsApplication.MainPage = carouselHost;
                }

                if (string.IsNullOrEmpty(page.Title))
                {
                    page.Title = attribute.Title;
                }
                carouselHost.Children.Add(page as ContentPage);
            }
        }