Exemple #1
0
        public virtual void ShowMasterDetailPage(
            Type view,
            MvxMasterDetailPagePresentationAttribute attribute,
            MvxViewModelRequest request)
        {
            var page = CloseAndCreatePage(view, request, attribute);

            if (attribute.Position == MasterDetailPosition.Root)
            {
                if (page is MasterDetailPage masterDetailRoot)
                {
                    if (masterDetailRoot.Master == null)
                    {
                        masterDetailRoot.Master = new MvxContentPage()
                        {
                            Title = !string.IsNullOrEmpty(attribute.Title) ? attribute.Title : nameof(MvxMasterDetailPage)
                        }
                    }
                    ;
                    if (masterDetailRoot.Detail == null)
                    {
                        masterDetailRoot.Detail = new MvxContentPage()
                        {
                            Title = !string.IsNullOrEmpty(attribute.Title) ? attribute.Title : nameof(MvxMasterDetailPage)
                        }
                    }
                    ;

                    PushOrReplacePage(FormsApplication.MainPage, page, attribute);
                }
                else
                {
                    throw new MvxException($"A root page should be of type {nameof(MasterDetailPage)}");
                }
            }
            else
            {
                var masterDetailHost = GetHostPageOfType <MvxMasterDetailPage>();
                if (masterDetailHost == null)
                {
                    //Assume we have to create the host
                    masterDetailHost = new MvxMasterDetailPage();

                    if (!string.IsNullOrWhiteSpace(attribute.Icon))
                    {
                        masterDetailHost.Icon = attribute.Icon;
                    }

                    masterDetailHost.Master = new MvxContentPage()
                    {
                        Title = !string.IsNullOrWhiteSpace(attribute.Title) ? attribute.Title : nameof(MvxMasterDetailPage)
                    };
                    masterDetailHost.Detail = new MvxContentPage();

                    var masterDetailRootAttribute = new MvxMasterDetailPagePresentationAttribute {
                        Position = MasterDetailPosition.Root, WrapInNavigationPage = attribute.WrapInNavigationPage, NoHistory = attribute.NoHistory
                    };

                    PushOrReplacePage(FormsApplication.MainPage, masterDetailHost, masterDetailRootAttribute);
                }

                if (attribute.Position == MasterDetailPosition.Master)
                {
                    PushOrReplacePage(masterDetailHost.Master, page, attribute);
                }
                else
                {
                    PushOrReplacePage(masterDetailHost.Detail, page, attribute);
                }
            }
        }
Exemple #2
0
        public virtual void ShowMasterDetailPage(
            Type view,
            MvxMasterDetailPagePresentationAttribute attribute,
            MvxViewModelRequest request)
        {
            CloseAllModals();
            ClosePlatformViews?.Invoke();

            var page = CreatePage(view, request, attribute);

            if (attribute.Position == MasterDetailPosition.Root)
            {
                if (page is MasterDetailPage masterDetailRoot)
                {
                    if (masterDetailRoot.Master == null)
                    {
                        masterDetailRoot.Master = new MvxContentPage()
                        {
                            Title = !string.IsNullOrEmpty(attribute.Title) ? attribute.Title : nameof(MvxMasterDetailPage)
                        }
                    }
                    ;
                    if (masterDetailRoot.Detail == null)
                    {
                        masterDetailRoot.Detail = new MvxContentPage()
                        {
                            Title = !string.IsNullOrEmpty(attribute.Title) ? attribute.Title : nameof(MvxMasterDetailPage)
                        }
                    }
                    ;

                    PushOrReplacePage(FormsApplication.MainPage, page, attribute);
                }
                else
                {
                    throw new MvxException($"A root page should be of type {nameof(MasterDetailPage)}");
                }
            }
            else
            {
                var masterDetailHost = GetHostPageOfType <MvxMasterDetailPage>();
                if (masterDetailHost == null)
                {
                    //Assume we have to create the host
                    masterDetailHost = new MvxMasterDetailPage();
                    if (attribute.Position == MasterDetailPosition.Master)
                    {
                        masterDetailHost.Master = page;
                    }
                    else
                    {
                        masterDetailHost.Master = new MvxContentPage()
                        {
                            Title = !string.IsNullOrEmpty(attribute.Title) ? attribute.Title : nameof(MvxMasterDetailPage)
                        }
                    };
                    if (attribute.Position == MasterDetailPosition.Detail)
                    {
                        masterDetailHost.Detail = page;
                    }
                    else
                    {
                        masterDetailHost.Detail = new MvxNavigationPage(new MvxContentPage()
                        {
                            Title = !string.IsNullOrEmpty(attribute.Title) ? attribute.Title : nameof(MvxMasterDetailPage)
                        });
                    }

                    PushOrReplacePage(FormsApplication.MainPage, masterDetailHost, attribute);
                }
                else if (attribute.Position == MasterDetailPosition.Master)
                {
                    PushOrReplacePage(masterDetailHost.Master, page, attribute);
                }
                else
                {
                    PushOrReplacePage(masterDetailHost.Detail, page, attribute);
                }
            }
        }