Пример #1
0
        /// <inheritdoc />
        public async Task PushAsync(BaseNavigationViewModel viewModel, bool discardCurrent = false)
        {
            var currentPage = FormsNavigation.NavigationStack.LastOrDefault();
            var view        = InstantiateView(viewModel);

            if (currentPage.BindingContext is INavigationAware navPrevious)
            {
                navPrevious.OnNavigatingFrom();
            }

            if (viewModel is INavigationAware navForward)
            {
                navForward.OnNavigatingTo();
            }

            await FormsNavigation.PushAsync((Page)view);

            if (viewModel is INavigationAware navigated)
            {
                navigated.OnNavigatedTo();
            }

            if (discardCurrent)
            {
                FormsNavigation.RemovePage(currentPage);
            }
        }
Пример #2
0
        /// <inheritdoc />
        public async Task PopToRootAsync(BaseNavigationViewModel vm, bool animate)
        {
            var navPage = InstantiateView(vm) as Page;

            var root = FormsNavigation.NavigationStack.First();

            FormsNavigation.InsertPageBefore(navPage, root);
            await FormsNavigation.PopToRootAsync(animate);
        }
Пример #3
0
        IViewFor InstantiateView(BaseNavigationViewModel viewModel)
        {
            // Figure out what type the view model is
            var viewModelType = viewModel.GetType();

            // look up what type of view it corresponds to
            var viewType = _viewModelViewDictionary[viewModelType];

            // instantiate it
            var view = (IViewFor)App.Container.Resolve(viewType);

            view.ViewModel = viewModel;

            return(view);
        }
Пример #4
0
        /// <inheritdoc />
        public void SwitchDetailPage(BaseNavigationViewModel viewModel)
        {
            var view = InstantiateView(viewModel);

            Page newDetailPage;

            // Tab pages shouldn't go into navigation pages
            if (view is TabbedPage)
            {
                newDetailPage = (Page)view;
            }
            else
            {
                newDetailPage = new NavigationPage((Page)view);
            }

            DetailPage = newDetailPage;
        }
Пример #5
0
        /// <inheritdoc />
        public async Task PushModalAsync(BaseNavigationViewModel viewModel)
        {
            viewModel.IsModal = true;

            var currentPage = FormsNavigation.NavigationStack.LastOrDefault();

            if (currentPage.BindingContext is INavigationAware navPrevious)
            {
                navPrevious.OnNavigatingFrom();
            }

            if (viewModel is INavigationAware navForward)
            {
                navForward.OnNavigatingTo();
            }

            var view = InstantiateView(viewModel);
            var nv   = new NavigationPage((Page)view);

            await FormsNavigation.PushModalAsync(nv);
        }