コード例 #1
0
        private bool TryShowPage(MvxViewModelRequest request)
        {
            var page = MvxPresenterHelpers.CreatePage(request);
            if (page == null)
                return false;

            var viewModel = MvxPresenterHelpers.LoadViewModel(request);

            SetupForBinding(page, request);

            var mainPage = _mvxFormsApp.MainPage as NavigationPage;

            if (mainPage == null)
            {
                _mvxFormsApp.MainPage = new NavigationPage(page);
                mainPage = MvxFormsApp.MainPage as NavigationPage;
                CustomPlatformInitialization(mainPage);
            }
            else
            {
                try
                {
					// calling this sync blocks UI and never navigates hence code continues regardless here
					mainPage.PushAsync(page);
                }
                catch (Exception e)
                {
                    Mvx.Error("Exception pushing {0}: {1}\n{2}", page.GetType(), e.Message, e.StackTrace);
                    return false;
                }
            }

            return true;
        }
コード例 #2
0
        private void SetupForBinding(Page page, MvxViewModelRequest request)
        {
            var viewModel = MvxPresenterHelpers.LoadViewModel(request);

            var mvxContentPage = page as IMvxContentPage;
            if (mvxContentPage != null) {
                mvxContentPage.Request = request;
                mvxContentPage.ViewModel = viewModel;
            } else {
                page.BindingContext = viewModel;
            }

        }
コード例 #3
0
        private bool TryShowPage(MvxViewModelRequest request)
        {
            var page = MvxPresenterHelpers.CreatePage(request);

            if (page == null)
            {
                return(false);
            }

            var viewModel = MvxPresenterHelpers.LoadViewModel(request);

            SetupForBinding(page, viewModel, request);

            var mainPage = _mvxFormsApp.MainPage as NavigationPage;

            if (mainPage == null)
            {
                _mvxFormsApp.MainPage = new NavigationPage(page);
                mainPage = MvxFormsApp.MainPage as NavigationPage;
                CustomPlatformInitialization(mainPage);
            }
            else
            {
                try
                {
                    // check for modal presentation parameter
                    string modalParameter;
                    if (request.PresentationValues != null && request.PresentationValues.TryGetValue(ModalPresentationParameter, out modalParameter) && bool.Parse(modalParameter))
                    {
                        mainPage.Navigation.PushModalAsync(page);
                    }
                    else
                    {
                        // calling this sync blocks UI and never navigates hence code continues regardless here
                        mainPage.PushAsync(page);
                    }
                }
                catch (Exception e)
                {
                    Mvx.Error("Exception pushing {0}: {1}\n{2}", page.GetType(), e.Message, e.StackTrace);
                    return(false);
                }
            }

            return(true);
        }
コード例 #4
0
        private bool TryShowPage(MvxViewModelRequest request)
        {
            var page = MvxPresenterHelpers.CreatePage(request);

            if (page == null)
            {
                return(false);
            }

            var viewModel = MvxPresenterHelpers.LoadViewModel(request);

            SetupForBinding(page, viewModel, request);

            var mainPage = _mvxFormsApp.MainPage as MasterDetailPage;

            // Initialize the MasterDetailPage container
            if (mainPage == null)
            {
                // The ViewModel used should inherit from MvxMasterDetailViewModel, so we can create a new ContentPage for use in the Detail page
                var masterDetailViewModel = viewModel as MvxMasterDetailViewModel;
                if (masterDetailViewModel == null)
                {
                    throw new InvalidOperationException("ViewModel should inherit from MvxMasterDetailViewModel<T>");
                }

                Page rootContentPage = null;
                if (masterDetailViewModel.RootContentPageViewModelType != null)
                {
                    var rootContentRequest = new MvxViewModelRequest(masterDetailViewModel.RootContentPageViewModelType, null, null, null);

                    var rootContentViewModel = MvxPresenterHelpers.LoadViewModel(rootContentRequest);
                    rootContentPage = MvxPresenterHelpers.CreatePage(rootContentRequest);
                    SetupForBinding(rootContentPage, rootContentViewModel, rootContentRequest);
                }
                else
                {
                    rootContentPage = new ContentPage();
                }

                var navPage = new NavigationPage(rootContentPage);

                //Hook to Popped event to launch RootContentPageActivated if proceeds
                navPage.Popped += (sender, e) =>
                {
                    if (navPage.Navigation.NavigationStack.Count == 1)
                    {
                        RootContentPageActivated();
                    }
                };

                mainPage = new MasterDetailPage
                {
                    Master = page,
                    Detail = navPage
                };

                _mvxFormsApp.MainPage = mainPage;
                CustomPlatformInitialization(mainPage);
            }
            else
            {
                // Functionality for clearing the navigation stack before pushing to new Page (for example in a menu with multiple options)
                if (request.PresentationValues != null)
                {
                    if (request.PresentationValues.ContainsKey("NavigationMode") && request.PresentationValues["NavigationMode"] == "ClearStack")
                    {
                        mainPage.Detail.Navigation.PopToRootAsync();
                        if (Device.Idiom == TargetIdiom.Phone)
                        {
                            mainPage.IsPresented = false;
                        }
                    }
                }

                try
                {
                    var nav = mainPage.Detail as NavigationPage;

                    // calling this sync blocks UI and never navigates hence code continues regardless here
                    nav.PushAsync(page);
                }
                catch (Exception e)
                {
                    Mvx.Error("Exception pushing {0}: {1}\n{2}", page.GetType(), e.Message, e.StackTrace);
                    return(false);
                }
            }

            return(true);
        }