Beispiel #1
0
        private async Task <bool> AdaptiveTryShowPage(MvxViewModelRequest request)
        {
            var page = MvxPresenterHelpers.CreatePage(request);

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

            var viewModel = MvvmCross.Forms.Presenter.Core.MvxPresenterHelpers.LoadViewModel(request);

            var mainPage = _mvxFormsApp.MainPage as NavigationPage;

            page.BindingContext = viewModel;

            if (mainPage == null)
            {
                _mvxFormsApp.MainPage = new NavigationPage(page);
                mainPage = (NavigationPage)_mvxFormsApp.MainPage;
                CustomPlatformInitialization(mainPage);
            }
            else
            {
                try
                {
                    await mainPage.PushAsync(page);
                }
                catch (System.Exception e)
                {
                    Mvx.Error("Exception pushing {0}: {1}\n{2}", page.GetType(), e.Message, e.StackTrace);
                }
            }

            return(true);
        }
        public override void Show(MvxViewModelRequest request)
        {
            //detect if we want a Forms View
            if (request.ViewModelType.FullName.Contains("XFViewModel"))
            {
                //get the Forms page from the request
                var contentPage = MvxPresenterHelpers.CreatePage(request);

                //set DataContext of page to LoadViewModel
                var viewModel = MvxPresenterHelpers.LoadViewModel(request);

                //set the binding context of the content page
                contentPage.BindingContext = viewModel;

                //set the current page of the activity
                MvxFormsApplicationActivity.CurrentPage = contentPage;

                //Start the Xamarin.Forms Activity
                Activity.StartActivity(typeof(MvxFormsApplicationActivity));
            }
            else
            {
                base.Show(request);
            }
        }
Beispiel #3
0
        public override void Show(MvxViewModelRequest request)
        {
            // XFViewModel means we need a Forms View
            if (request.ViewModelType.FullName.Contains("XFViewModel"))
            {
                //get the xamarin.forms page from the ViewModel
                var contentPage = MvxPresenterHelpers.CreatePage(request);

                //MvvmCross call to create the view model with DI etc
                var viewModel = MvxPresenterHelpers.LoadViewModel(request);

                //Assign it to the Forms Binding Content
                contentPage.BindingContext = viewModel;

                //Creating the view controller from the content page
                var viewController = contentPage.CreateViewController();

                if (this.MasterNavigationController == null)
                {
                    // If it's the first view
                    this.ShowFirstView(viewController);
                }
                else
                {
                    // If it's already in the stack
                    this.MasterNavigationController.PushViewController(viewController, true);
                }
            }
            else
            {
                //Using a normal MvvmCross View
                base.Show(request);
            }
        }
        public override void Show(MvxViewModelRequest request)
        {
            if (request.ViewModelType.FullName.Contains("XamarinViewModel"))
            {
                var contentPage = MvxPresenterHelpers.CreatePage(request);
                //set DataContext of page to LoadViewModel
                var viewModel = MvxPresenterHelpers.LoadViewModel(request);

                contentPage.BindingContext = viewModel;
                //use CreateViewController

                var uIViewController = contentPage.CreateViewController();
                if (this.MasterNavigationController == null)
                {
                    this.ShowFirstView(uIViewController);
                }
                else
                {
                    this.MasterNavigationController.PushViewController(uIViewController, true);
                }
            }
            else
            {
                base.Show(request);
            }
        }
        private async Task <bool> TryShowPage(MvxViewModelRequest request)
        {
            var page = MvxPresenterHelpers.CreatePage(request);

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

            var viewModel = MvxPresenterHelpers.LoadViewModel(request);

            if (_navigationPage == null)
            {
                Forms.Init();
                _navigationPage            = new NavigationPage(page);
                _window.RootViewController = _navigationPage.CreateViewController();
            }
            else
            {
                await _navigationPage.PushAsync(page);
            }

            page.BindingContext = viewModel;
            return(true);
        }
        protected Page ResolvePage(MvxViewModelRequest request)
        {
            var page = MvxPresenterHelpers.CreatePage(request);

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

            var viewModel = MvxPresenterHelpers.LoadViewModel(request);

            page.BindingContext = viewModel;
            return(page);
        }
        public override void Show(MvxViewModelRequest request)
        {
            var viewFromXF = request.ViewModelType.GetCustomAttributes(typeof(ViewFromXamarinFormsAttribute), false);

            if (viewFromXF.Any())
            {
                // get the Forms page from the request
                var contentPage = MvxPresenterHelpers.CreatePage(request);

                //set DataContext of page to LoadViewModel
                var viewModel = MvxPresenterHelpers.LoadViewModel(request);

                //set the binding context of the content page
                contentPage.BindingContext = viewModel;

                var mainPage = mvxFormsApp.MainPage as NavigationPage;

                if (mainPage == null)
                {
                    // XF application exists but no Root.
                    this.InitialiseXfActivityStack(contentPage);
                }
                else
                {
                    try
                    {
                        if (this.Activity is MvxFormsApplicationActivity == false)
                        {
                            // XF application exists and there is a Root however the TopMostActivity
                            // (this.Activity) is not MvxFormsApplicationActivity. We must be back in Native world
                            // Restart XF stack
                            this.InitialiseXfActivityStack(contentPage);
                        }
                        else
                        {
                            mainPage.PushAsync(contentPage);
                        }
                    }
                    catch (Exception e)
                    {
                        Mvx.Error("Exception pushing {0}: {1}\n{2}", contentPage.GetType(), e.Message, e.StackTrace);
                    }
                }
            }
            else
            {
                base.Show(request);
            }
        }
        public override void Show(MvxViewModelRequest request)
        {
            if (request.ViewModelType == typeof(ThirdViewModel) || request.ViewModelType == typeof(FourthViewModel))
            {
                var contentPage = MvxPresenterHelpers.CreatePage(request);
                //set DataContext of page to LoadViewModel
                var viewModel = MvxPresenterHelpers.LoadViewModel(request);

                contentPage.BindingContext = viewModel;
                //use CreateViewController

                var mainPage = _mvxFormsApp.MainPage as NavigationPage;

                if (mainPage == null)
                {
                    _mvxFormsApp.MainPage = new NavigationPage(contentPage);
                    mainPage = MvxFormsApp.MainPage as NavigationPage;
                }
                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);
            }
            else
            {
                base.Show(request);
            }
        }
        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 = _formsApplication.MainPage as NavigationPage;

            if (mainPage == null)
            {
                _formsApplication.MainPage = new NavigationPage(page);
                mainPage = FormsApplication.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);
        }
        public override void Show(MvxViewModelRequest request)
        {
            if (request.ViewModelType.FullName.Contains("XamarinViewModel"))
            {
                var contentPage = MvxPresenterHelpers.CreatePage(request);
                //set DataContext of page to LoadViewModel
                var viewModel = MvxPresenterHelpers.LoadViewModel(request);

                contentPage.BindingContext = viewModel;

                MvxFormsApplicationActivity.CurrentPage = contentPage;
                this.Activity.StartActivity(typeof(MvxFormsApplicationActivity));
            }
            else
            {
                base.Show(request);
            }
            _navigationStack.Push(request);
        }
        public override async Task <bool> Show(MvxViewModelRequest request)
        {
            // XFViewModel means we need a Forms View
            if (request.ViewModelType.FullName.Contains("XFViewModel"))
            {
                //get the xamarin.forms page from the ViewModel
                var contentPage = MvxPresenterHelpers.CreatePage(request);

                //MvvmCross call to create the view model with DI etc
                var viewModel = MvxPresenterHelpers.LoadViewModel(request);

                //Assign it to the Forms Binding Content
                contentPage.BindingContext = viewModel;

                //Creating the view controller from the content page
                var viewController = contentPage.CreateViewController();
                viewController.Title = contentPage.Title;

                if (this.MasterNavigationController == null)
                {
                    // If it's the first view
                    MvxRootPresentationAttribute attribute = new MvxRootPresentationAttribute()
                    {
                        AnimationDuration = MvxRootPresentationAttribute.DefaultAnimationDuration,
                        AnimationOptions  = MvxRootPresentationAttribute.DefaultAnimationOptions,
                        ViewModelType     = request.ViewModelType
                    };

                    return(await this.ShowRootViewController(viewController, attribute, request));
                }
                else
                {
                    // If it's already in the stack
                    this.MasterNavigationController.PushViewController(viewController, true);
                    return(await Task.FromResult(true));
                }
            }
            else
            {
                //Using a normal MvvmCross View
                return(await base.Show(request));
            }
        }
Beispiel #12
0
        private bool TryShowPage(MvxViewModelRequest request)
        {
            if (this.NavigationProvider == null)
            {
                return(false);
            }

            var page = MvxPresenterHelpers.CreatePage(request);

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

            var viewModel = MvxPresenterHelpers.LoadViewModel(request);

            page.BindingContext = viewModel;

            this.NavigationProvider.Push(page);

            return(true);
        }
      public override void Show(MvxViewModelRequest request)
      {
          var viewFromXf = request.ViewModelType.GetCustomAttributes(typeof(ViewFromXamarinFormsAttribute), false);

          if (viewFromXf.Any())
          {
              var contentPage = MvxPresenterHelpers.CreatePage(request);
              //set DataContext of page to LoadViewModel
              var viewModel = MvxPresenterHelpers.LoadViewModel(request);

              contentPage.BindingContext = viewModel;

              var mainPage = this.MvxFormsApp.MainPage as NavigationPage;

              if (mainPage == null)
              {
                  this.MvxFormsApp.MainPage = new NavigationPage(contentPage);
                  mainPage = MvxFormsApp.MainPage as NavigationPage;
              }

              UIViewController vc = contentPage.CreateViewController();

              vc.NavigationItem.Title = contentPage.Title;

              if (this.MasterNavigationController == null)
              {
                  _window.RootViewController = vc;
              }
              else
              {
                  this.MasterNavigationController.PushViewController(vc, true);
              }
          }
          else
          {
              base.Show(request);
          }
      }
Beispiel #14
0
        protected override void OnElementChanged(Xamarin.Forms.Platform.Android.ElementChangedEventArgs <Xamarin.Forms.Page> e)
        {
            base.OnElementChanged(e);

            MvxPresenterHelpers.AdaptForBinding(Element, this);
        }
Beispiel #15
0
        protected override void OnElementChanged(ElementChangedEventArgs <Page> e)
        {
            base.OnElementChanged(e);

            MvxPresenterHelpers.AdaptForBinding(Element, this);
        }
        private bool TryShowMasterDetailPage(MvxViewModelRequest request)
        {
            var page = MvxPresenterHelpers.CreatePage(request);

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

            var viewModel = MvxPresenterHelpers.LoadViewModel(request);

            SetupMasterDetailForBinding(page, viewModel, request);

            var mainPage = FormsApplication.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;
                if (masterDetailViewModel.RootContentPageViewModelType != null)
                {
                    var rootContentRequest = new MvxViewModelRequest(masterDetailViewModel.RootContentPageViewModelType, null, null);

                    var rootContentViewModel = MvxPresenterHelpers.LoadViewModel(rootContentRequest);
                    rootContentPage = MvxPresenterHelpers.CreatePage(rootContentRequest);
                    SetupMasterDetailForBinding(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)
                    {
                        MasterRootContentPageActivated();
                    }
                };

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

                FormsApplication.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);
        }
Beispiel #17
0
        protected override void OnElementChanged(Xamarin.Forms.Platform.iOS.VisualElementChangedEventArgs e)
        {
            base.OnElementChanged(e);

            MvxPresenterHelpers.AdaptForBinding(Element, this);
        }
        public async Task <bool> TryShowAsync(MvxViewModelRequest request)
        {
            try
            {
                var requestType = GetRequestType(request);

                //Allow the navigation in case this is a root/modal request, otherwise ignore the request if busy
                if (_isBusy && (requestType != RequestType.Root))
                {
                    return(false);
                }

                _isBusy = true;

                var page = MvxPresenterHelpers.CreatePage(request);
                (page as BaseView)?.OnInitialized();

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

                var viewModel = MvxPresenterHelpers.LoadViewModel(request);

                bool result;
                switch (requestType)
                {
                case RequestType.MasterDetail:
                    result = await HandleMasterDetailRequest(page, viewModel);

                    break;

                case RequestType.Root:
                    result = await HandleRootNavigationRequest(page, viewModel);

                    break;

                case RequestType.Modal:
                    result = await HandleModalNavigationRequest(page, viewModel);

                    break;

                case RequestType.PreAppStart:
                    result = await HandlePreAppStartRequest(page, viewModel);

                    break;

                case RequestType.Clean:
                    result = await HandleCleanNavigationRequest(page, viewModel);

                    break;

                case RequestType.None:
                    result = await HandleGeneralNavigationRequest(page, viewModel);

                    break;

                default:
                    result = await HandleGeneralNavigationRequest(page, viewModel);

                    break;
                }

                if (result)
                {
                    OnPagePresented(page);
                }

                return(result);
            }
            catch (Exception ex)
            {
                Logger.Exception(nameof(TryShowAsync), ex);

                return(false);
            }
            finally
            {
                IsShowingModalView = false;
                _isBusy            = false;
            }
        }