Example #1
0
        private async Task <bool> NavingFromAsync(Portable.INavigatingAwareAsync viewmodel, Page page, object currentParameter, bool suspending, NavigationMode navigationMode, Type targetPageType, object targetParameter)
        {
            var deferral            = new Template10.Mobile.Common.DeferralManager();
            var navigatingEventArgs = new Portable.NavigatingEventArgs(deferral)
            {
                Page                = page,
                Parameter           = currentParameter,
                Suspending          = suspending,
                NavigationMode      = navigationMode.ToTemplate10NavigationMode(),
                TargetPageType      = targetPageType,
                TargetPageParameter = targetParameter,
            };

            try
            {
                await viewmodel.OnNavigatingFromAsync(navigatingEventArgs);

                await deferral.WaitForDeferralsAsync();
            }
            catch
            {
                Debugger.Break();
            }
            return(navigatingEventArgs.Cancel);
        }
Example #2
0
        public async Task NavedToAsync(object viewmodel, object parameter, NavigationMode mode, Page page)
        {
            Services.NavigationService.NavigationService.DebugWrite();

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

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

            if (viewmodel == null)
            {
                return;
            }
            else if (viewmodel is Classic.INavigatedAwareAsync)
            {
                var vm = viewmodel as Classic.INavigatedAwareAsync;
                await vm?.OnNavigatedToAsync(parameter, mode, PageState(page));
            }
            else if (viewmodel is Portable.INavigatedAwareAsync)
            {
                var vm = viewmodel as Portable.INavigatedAwareAsync;
                await vm?.OnNavigatedToAsync(parameter, mode.ToTemplate10NavigationMode(), PageState(page));
            }

            page.InitializeBindings();
            page.UpdateBindings();
        }
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 oldViewModel = oldPage?.DataContext;

            // call oldViewModel.OnNavigatingFromAsync()
            var viewmodelCancels = await Navigation.NavingFromCancelsAsync(oldViewModel, oldPage, CurrentPageParam, false, mode, page, parameter);

            if (viewmodelCancels)
            {
                return(false);
            }

            // raise Navigating event
            var eventCancels = RaiseNavigatingCancels(oldPage, parameter, false, mode.ToTemplate10NavigationMode(), 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.ToTemplate10NavigationMode());

            // call oldViewModel.OnNavigatedFrom()
            await Navigation.NavedFromAsync(oldViewModel, oldPage, false);

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

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

            // call newViewModel.OnNavigatedToAsync()
            await Navigation.NavedToAsync(newViewModel, parameter, mode, newPage);

            // finally
            return(true);
        }