Esempio n. 1
0
        private async Task <INavigationResult> NavigateAsync(
            NavigationQueue queue,
            NavigationTransitionInfo infoOverride)
        {
            Debug.WriteLine($"{nameof(FrameFacade)}.{nameof(NavigateAsync)}({queue})");

            // clear stack, if requested

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

            // iterate through queue

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

                var result = await NavigateAsync(
                    pageNavInfo : pageNavinfo,
                    infoOverride : infoOverride);

                // do not continue on failure

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

            // finally

            return(NavigationResult.Successful());
        }
Esempio n. 2
0
        public async Task <INavigationResult> GoForwardAsync()
        {
            if (!CanGoForward())
            {
                return(NavigationResult.Failure($"{nameof(CanGoForward)} is false."));
            }

            return(await OrchestrateAsync(
                       parameters : null,
                       mode : Prism.Navigation.NavigationMode.Forward,
                       navigate : async() =>
            {
                _frame.GoForward();
                return true;
            }));
        }
Esempio n. 3
0
        public async Task <INavigationResult> GoBackAsync(INavigationParameters parameters,
                                                          NavigationTransitionInfo infoOverride)
        {
            if (!CanGoBack())
            {
                return(NavigationResult.Failure($"{nameof(CanGoBack)} is false."));
            }

            return(await OrchestrateAsync(
                       parameters : parameters,
                       mode : Prism.Navigation.NavigationMode.Back,
                       navigate : async() =>
            {
                _frame.GoBack(infoOverride);
                return true;
            }));
        }
Esempio n. 4
0
        private async Task <INavigationResult> OrchestrateAsync(
            INavigationParameters parameters,
            Prism.Navigation.NavigationMode mode,
            Func <Task <bool> > navigate)
        {
            // setup default parameters

            parameters = CreateDefaultParameters(parameters, mode);

            // pre-events

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

            if (old_vm == null)
            {
                Debug.WriteLine($"[From]View-Model is null.");
            }
            else if (!await CanNavigateAsync(parameters, old_vm))
            {
                return(NavigationResult.Failure($"[From]{old_vm}.CanNavigateAsync returned false."));
            }
            else if (!CanNavigate(parameters, old_vm))
            {
                return(NavigationResult.Failure($"[From]{old_vm}.CanNavigate returned false."));
            }

            // navigate

            var success = await NavigateFrameAsync(navigate);

            Debug.WriteLine($"{nameof(FrameFacade)}.{nameof(OrchestrateAsync)}.NavigateFrameAsync() returned {success}.");
            if (!success)
            {
                return(NavigationResult.Failure("NavigateFrameAsync() returned false."));
            }

            var new_page = _frame.Content as Page;

            if (new_page == null)
            {
                throw new Exception("There is no new page in Frame after Navigate.");
            }

            // post-events

            if (old_vm != null)
            {
                OnNavigatedFrom(parameters, old_vm);
            }

            var new_vm = new_page?.DataContext;

            if (new_vm == null)
            {
                if (Central.Registry.TryGetRegistration(_frame.CurrentSourcePageType, out var info) && info.ViewModel != null)
                {
                    new_page.DataContext = new_vm = Central.Container.Resolve(info.ViewModel);
                }
            }

            if (new_vm == null)
            {
                Debug.WriteLine($"[To]View-Model is null.");
            }
            else
            {
                await OnNavigatedToAsync(parameters, new_vm);

                OnNavigatingTo(parameters, new_vm);
                OnNavigatedTo(parameters, new_vm);
            }

            // refresh-bindings

            BindingUtilities.UpdateBindings(new_page);

            // finally

            return(NavigationResult.Successful());
        }