Пример #1
0
        public async Task NavedFromAsync(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;
            }
            else if (viewmodel == null)
            {
                return;
            }
            else if (viewmodel is Classic.INavigatedAwareAsync)
            {
                var vm = viewmodel as Classic.INavigatedAwareAsync;
                await vm?.OnNavigatedFromAsync(PageState(sourcePage), suspending);
            }
            else if (viewmodel is Portable.INavigatedAware)
            {
                var vm = viewmodel as Portable.INavigatedAware;
                var parameters = new Portable.NavigationParameters();
                vm?.OnNavigatedFrom(parameters);
            }
            else if (viewmodel is Portable.INavigatedAwareAsync)
            {
                var vm = viewmodel as Portable.INavigatedAwareAsync;
                var parameters = new Portable.NavigationParameters();
                await vm?.OnNavigatedFromAsync(parameters);
            }
        }
Пример #2
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();
        }
Пример #3
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;
            }
        }