コード例 #1
0
        public async Task <INavigationResult> GoForwardAsync()
        {
            try
            {
                if (!CanGoForward())
                {
                    return(NavigationResult.Failure($"{nameof(CanGoForward)} is false."));
                }

                Func <bool> navigate = () =>
                {
                    _frame.GoForward();
                    return(true);
                };

                return(await OrchestrateNavigation(
                           parameters : null,
                           mode : NavigationMode.Forward,
                           navigate : navigate));
            }
            catch (Exception ex)
            {
                return(NavigationResult.Failure(ex));
            }
        }
コード例 #2
0
        public async Task <INavigationResult> GoBackAsync(INavigationParameters parameters, NavigationTransitionInfo infoOverride)
        {
            try
            {
                if (!CanGoBack())
                {
                    return(NavigationResult.Failure($"{nameof(CanGoBack)} is false."));
                }

                Func <bool> navigate = () =>
                {
                    _frame.GoBack(infoOverride);
                    return(true);
                };

                return(await OrchestrateNavigation(
                           parameters : parameters,
                           mode : NavigationMode.Back,
                           navigate : navigate));
            }
            catch (Exception ex)
            {
                return(NavigationResult.Failure(ex));
            }
        }
コード例 #3
0
        public async Task <INavigationResult> RefreshAsync()
        {
            try
            {
                Func <bool> navigate = () =>
                {
                    _frame.SetNavigationState(_frame.GetNavigationState());
                    return(!_frame.BackStack.Any());
                };

                return(await OrchestrateNavigation(
                           parameters : null,
                           mode : NavigationMode.Refresh,
                           navigate : navigate));
            }
            catch (Exception ex)
            {
                return(NavigationResult.Failure(ex));
            }
        }
コード例 #4
0
        public async Task <INavigationResult> NavigateAsync(Uri uri, INavigationParameters parameter, NavigationTransitionInfo infoOverride)
        {
            try
            {
                var queue = PageNavigationRegistry.ParsePath(uri, parameter);

                if (queue.ClearBackStack)
                {
                    _frame.SetNavigationState(new Frame().GetNavigationState());
                }

                while (queue.Count > 0)
                {
                    var pageNavigationInfo = queue.Dequeue();

                    Func <bool> navigate = () => _frame.Navigate(
                        sourcePageType: pageNavigationInfo.Page,
                        parameter: pageNavigationInfo.Parameters,
                        infoOverride: infoOverride);

                    Func <Task <INavigationResult> > orchestrate = async() => await OrchestrateNavigation(
                        parameters : parameter,
                        mode : NavigationMode.New,
                        navigate : navigate);

                    var result = await orchestrate();

                    if (!result.Success)
                    {
                        return(result);
                    }
                }

                return(NavigationResult.Successful());
            }
            catch (Exception ex)
            {
                return(NavigationResult.Failure(ex));
            }
        }
コード例 #5
0
        private async Task <INavigationResult> OrchestrateNavigation(INavigationParameters parameters, Prism.Navigation.NavigationMode mode, Func <bool> navigate)
        {
            // default parameters

            parameters = parameters ?? new NavigationParameters();
            parameters.SetNavigationMode(mode);
            parameters.SetNavigationService(_navigationService);

            // hold prev vm

            var old_vm = (_frame.Content as Page)?.DataContext;

            // CanNavigateAsync

            if (old_vm is IConfirmNavigationAsync old_vm_confirma)
            {
                if (!await old_vm_confirma.CanNavigateAsync(parameters))
                {
                    return(NavigationResult.Failure($"{old_vm_confirma}.CanNavigateAsync returned false."));
                }
            }

            // CanNavigate

            if (old_vm is IConfirmNavigation old_vm_confirms)
            {
                if (!old_vm_confirms.CanNavigate(parameters))
                {
                    return(NavigationResult.Failure($"{old_vm_confirms}.CanNavigate returned false."));
                }
            }

            // navigate

            await NavigateInternalAsync(navigate);

            // OnNavigatedFrom

            if (old_vm is INavigatedAware old_vm_ed)
            {
                old_vm_ed.OnNavigatedFrom(parameters);
            }

            // hold new vm

            var new_vm = (_frame.Content as Page)?.DataContext;

            // OnNavigatingTo

            if (new_vm is INavigatingAware new_vm_ing)
            {
                new_vm_ing.OnNavigatingTo(parameters);
            }

            // OnNavigatedTo

            if (new_vm is INavigatedAware new_vm_ed)
            {
                new_vm_ed.OnNavigatedTo(parameters);
            }

            // finally

            return(NavigationResult.Successful());
        }