예제 #1
0
        /// <summary>
        /// Creates a page associated with the ViewModel and pushes it on the navigation stack.
        /// </summary>
        /// <param name="viewModelType">The ViewModel to associate and bind.</param>
        /// <param name="parameter">Any parameters required by the ViewModel.</param>
        /// <returns>A Task.</returns>
        private async Task InternalNavigateToAsync(Type viewModelType, object parameter = null)
        {
            Page page = null;

            try
            {
                page = this.CreateAndBindPage(viewModelType, parameter);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            if (page is MainView)
            {
                this.CurrentApplication.MainPage = page;
            }
            else if (this.CurrentApplication.MainPage is MainView)
            {
                var mainPage = this.CurrentApplication.MainPage as MainView;

                if (mainPage.Detail is DefaultNavigationPage navigationPage)
                {
                    var currentPage = navigationPage.CurrentPage;

                    if (currentPage.GetType() != page.GetType())
                    {
                        await navigationPage.PushAsync(page);
                    }
                }
                else
                {
                    navigationPage  = new DefaultNavigationPage(page);
                    mainPage.Detail = navigationPage;
                }

                mainPage.IsPresented = false;
            }
            else
            {
                var navigationPage = this.CurrentApplication.MainPage as DefaultNavigationPage;

                if (navigationPage != null)
                {
                    await navigationPage.PushAsync(page);
                }
                else
                {
                    this.CurrentApplication.MainPage = new DefaultNavigationPage(page);
                }
            }

            await(page.BindingContext as ViewModelBase).InitializeAsync(parameter);
        }
예제 #2
0
        public App()
        {
            app = this;

            RegisterDependencies();

            /* if we were targeting Windows Phone, we'd want to include the next line. */
            // if (Device.OS != TargetPlatform.WinPhone)
            TextResources.Culture = DependencyService.Get <ILocalize>().GetCurrentCultureInfo();

            _AuthenticationService = DependencyService.Get <IAuthenticationService>();

            // If the App.IsAuthenticated property is false, modally present the SplashPage.
            if (!_AuthenticationService.IsAuthenticated)
            {
                MainPage = new DefaultNavigationPage(new WelcomePage());
            }
            else
            {
                GoToRoot();
            }
            NavigationPage.SetHasNavigationBar(this, false);
        }