Example #1
0
        public async Task NavedToAsync(object viewmodel, NavigationMode mode, Page sourcePage, Type sourceType, object sourceParameter, Page targetPage, Type targetType, object targetParameter)
        {
            Services.NavigationService.NavigationService.DebugWrite();

            if (targetPage == null)
            {
                throw new ArgumentNullException(nameof(targetPage));
            }

            if (mode == NavigationMode.New)
            {
                PageState(targetPage).Clear();
            }

            if (viewmodel == null)
            {
                return;
            }
            else if (viewmodel is Classic.INavigatedAwareAsync)
            {
                var vm = viewmodel as Classic.INavigatedAwareAsync;
                await vm?.OnNavigatedToAsync(targetParameter, mode, PageState(targetPage));
            }
            else if (viewmodel is Portable.INavigatedAware)
            {
                var parameters = new Portable.NavigationParameters();
                parameters.Add("NavigationMode", mode.ToPrismNavigationMode());
                parameters.Add("SourceType", sourceType);
                parameters.Add("SourceParameter", sourceParameter);
                parameters.Add("TargetType", targetType);
                parameters.Add("TargetParameter", targetParameter);
                var vm = viewmodel as Portable.INavigatedAware;
                vm?.OnNavigatedTo(parameters);
            }
            else if (viewmodel is Portable.INavigatedAwareAsync)
            {
                var parameters = new Portable.NavigationParameters();
                parameters.Add("NavigationMode", mode.ToPrismNavigationMode());
                parameters.Add("SourceType", sourceType);
                parameters.Add("SourceParameter", sourceParameter);
                parameters.Add("TargetType", targetType);
                parameters.Add("TargetParameter", targetParameter);
                var vm = viewmodel as Portable.INavigatedAwareAsync;
                await vm?.OnNavigatedToAsync(parameters);
            }

            targetPage.InitializeBindings();
            targetPage.UpdateBindings();
        }
Example #2
0
        public async Task <bool> NavingFromCancelsAsync(object viewmodel, NavigationMode mode, Page sourcePage, Type sourceType, object sourceParameter, Page targetPage, Type targetType, object targetParameter, bool suspending)
        {
            Services.NavigationService.NavigationService.DebugWrite();

            if (sourcePage == null)
            {
                return(false);
            }
            else if (viewmodel == null)
            {
                return(false);
            }
            else if (viewmodel is Classic.INavigatingAwareAsync)
            {
                var deferral            = new DeferralManager();
                var navigatingEventArgs = new Classic.NavigatingEventArgs(deferral)
                {
                    Page                = sourcePage,
                    PageType            = sourcePage?.GetType(),
                    Parameter           = sourceParameter,
                    NavigationMode      = mode,
                    TargetPageType      = targetType,
                    TargetPageParameter = targetParameter,
                    Suspending          = suspending,
                };
                try
                {
                    var vm = viewmodel as Classic.INavigatingAwareAsync;
                    await vm?.OnNavigatingFromAsync(navigatingEventArgs);

                    await deferral.WaitForDeferralsAsync();
                }
                catch
                {
                    Debugger.Break();
                }
                return(navigatingEventArgs.Cancel);
            }
            else if (viewmodel is Portable.IConfirmNavigationAsync)
            {
                var parameters = new Portable.NavigationParameters();
                parameters.Add("NavigationMode", mode.ToPrismNavigationMode());
                parameters.Add("SourceType", sourceType);
                parameters.Add("SourceParameter", sourceParameter);
                parameters.Add("TargetType", targetType);
                parameters.Add("TargetParameter", targetParameter);
                parameters.Add("Suspending", suspending);
                var vm = viewmodel as Portable.IConfirmNavigationAsync;
                return(!await vm?.CanNavigateAsync(parameters));
            }
            else
            {
                return(true);
            }
        }
Example #3
0
        private async Task <bool> NavigationOrchestratorAsync(Type page, object parameter, NavigationMode mode, Func <bool> navigate)
        {
            DebugWrite($"Page: {page}, Parameter: {parameter}, NavigationMode: {mode}");

            if (page == null)
            {
                throw new ArgumentNullException(nameof(page));
            }
            if (navigate == null)
            {
                throw new ArgumentNullException(nameof(navigate));
            }

            // this cannot be used for duplicate navigation, except for refresh
            if ((mode != NavigationMode.Refresh) &&
                (page.FullName == CurrentPageType?.GetType().FullName) &&
                (parameter?.Equals(CurrentPageParam) ?? false))
            {
                return(false);
            }

            // fetch current (which will become old)
            var oldPage      = FrameFacade.Content as Page;
            var oldParameter = CurrentPageParam;
            var oldViewModel = oldPage?.DataContext;

            // call oldViewModel.OnNavigatingFromAsync()
            var viewmodelCancels = await Navigation.NavingFromCancelsAsync(oldViewModel, mode, FrameFacade.Content as Page, CurrentPageType, CurrentPageParam, null, page, parameter, false);

            if (viewmodelCancels)
            {
                return(false);
            }

            // raise Navigating event
            var eventCancels = RaiseNavigatingCancels(oldPage, parameter, false, mode.ToPrismNavigationMode(), page);

            if (eventCancels)
            {
                return(false);
            }

            // invoke navigate (however custom)
            if (navigate.Invoke())
            {
                CurrentPageParam = parameter;
                CurrentPageType  = page;
            }
            else
            {
                return(false);
            }

            // fetch (current which is now new)
            var newPage      = FrameFacade.Content as Page;
            var newViewModel = newPage?.DataContext;

            // raise Navigated event
            RaiseNavigated(newPage, parameter, mode.ToPrismNavigationMode());

            // call oldViewModel.OnNavigatedFrom()
            await Navigation.NavedFromAsync(oldViewModel, mode, oldPage, oldPage?.GetType(), oldParameter, newPage, page, parameter, false);

            // call newViewModel.ResolveForPage()
            if (newViewModel == null)
            {
                newViewModel        = BootStrapper.Current.ResolveForPage(newPage, this);
                newPage.DataContext = newViewModel;
            }

            // call newTemplate10ViewModel.Properties
            if (newViewModel is ITemplate10ViewModel)
            {
                Navigation.SetupViewModel(this, newViewModel as ITemplate10ViewModel);
            }

            // call newViewModel.OnNavigatedToAsync()
            await Navigation.NavedToAsync(newViewModel, mode, oldPage, oldPage?.GetType(), oldParameter, newPage, page, parameter);

            // finally
            return(true);
        }
Example #4
0
        public async Task NavedToAsync(object viewmodel, NavigationMode mode, Page sourcePage, Type sourceType, object sourceParameter, Page targetPage, Type targetType, object targetParameter)
        {
            Services.NavigationService.NavigationService.DebugWrite();

            if (targetPage == null)
            {
                throw new ArgumentNullException(nameof(targetPage));
            }

            if (mode == NavigationMode.New)
            {
                PageState(targetPage).Clear();
            }

            if (viewmodel == null)
            {
                return;
            }
            else if (viewmodel is Classic.INavigatedAwareAsync)
            {
                var vm = viewmodel as Classic.INavigatedAwareAsync;
                await vm?.OnNavigatedToAsync(targetParameter, mode, PageState(targetPage));
            }
            else if (viewmodel is Portable.INavigatedAware)
            {
                var parameters = new Portable.NavigationParameters();
                parameters.Add("NavigationMode", mode.ToPrismNavigationMode());
                parameters.Add("SourceType", sourceType);
                parameters.Add("SourceParameter", sourceParameter);
                parameters.Add("TargetType", targetType);
                parameters.Add("TargetParameter", targetParameter);
                var vm = viewmodel as Portable.INavigatedAware;
                vm?.OnNavigatedTo(parameters);
            }
            else if (viewmodel is Portable.INavigatedAwareAsync)
            {
                var parameters = new Portable.NavigationParameters();
                parameters.Add("NavigationMode", mode.ToPrismNavigationMode());
                parameters.Add("SourceType", sourceType);
                parameters.Add("SourceParameter", sourceParameter);
                parameters.Add("TargetType", targetType);
                parameters.Add("TargetParameter", targetParameter);
                var vm = viewmodel as Portable.INavigatedAwareAsync;
                await vm?.OnNavigatedToAsync(parameters);
            }

            targetPage.InitializeBindings();
            targetPage.UpdateBindings();
        }
Example #5
0
        public async Task<bool> NavingFromCancelsAsync(object viewmodel, NavigationMode mode, Page sourcePage, Type sourceType, object sourceParameter, Page targetPage, Type targetType, object targetParameter, bool suspending)
        {
            Services.NavigationService.NavigationService.DebugWrite();

            if (sourcePage == null)
            {
                return false;
            }
            else if (viewmodel == null)
            {
                return false;
            }
            else if (viewmodel is Classic.INavigatingAwareAsync)
            {
                var deferral = new DeferralManager();
                var navigatingEventArgs = new Classic.NavigatingEventArgs(deferral)
                {
                    Page = sourcePage,
                    PageType = sourcePage?.GetType(),
                    Parameter = sourceParameter,
                    NavigationMode = mode,
                    TargetPageType = targetType,
                    TargetPageParameter = targetParameter,
                    Suspending = suspending,
                };
                try
                {
                    var vm = viewmodel as Classic.INavigatingAwareAsync;
                    await vm?.OnNavigatingFromAsync(navigatingEventArgs);
                    await deferral.WaitForDeferralsAsync();
                }
                catch
                {
                    Debugger.Break();
                }
                return navigatingEventArgs.Cancel;
            }
            else if (viewmodel is Portable.IConfirmNavigationAsync)
            {
                var parameters = new Portable.NavigationParameters();
                parameters.Add("NavigationMode", mode.ToPrismNavigationMode());
                parameters.Add("SourceType", sourceType);
                parameters.Add("SourceParameter", sourceParameter);
                parameters.Add("TargetType", targetType);
                parameters.Add("TargetParameter", targetParameter);
                parameters.Add("Suspending", suspending);
                var vm = viewmodel as Portable.IConfirmNavigationAsync;
                return !await vm?.CanNavigateAsync(parameters);
            }
            else
            {
                return true;
            }
        }