private async Task OnNavigatingFromAsync(NavigatingCancelEventArgs e, IHandleNavigatingFrom handler) { var navigationServiceNavigatingCancelEventArgs = e.ToNavigationServiceNavigatingCancelEventArgs(); await InvokeHandlerOnNavigatingFromAsync(handler, navigationServiceNavigatingCancelEventArgs); if (!navigationServiceNavigatingCancelEventArgs.Cancel) { _alreadyPerformedOnNavigatingFrom = true; #if WINDOWS_PHONE || WINDOWS_PHONE_81 Dispatcher.BeginInvoke(() => { var frame = this.GetVisualAncestor <Frame>(); switch (e.NavigationMode) { case NavigationMode.New: frame.Navigate(e.Uri); break; #else await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { var frame = this.Frame; switch (e.NavigationMode) { case NavigationMode.New: frame.Navigate(e.SourcePageType, e.Parameter, e.NavigationTransitionInfo); break; #endif case NavigationMode.Back: frame.GoBack(); break; case NavigationMode.Forward: frame.GoForward(); break; } }); } } } }
private async Task OnNavigatingFromAsync(NavigatingCancelEventArgs e, IHandleNavigatingFrom handler) { var navigationServiceNavigatingCancelEventArgs = e.ToNavigationServiceNavigatingCancelEventArgs(); await InvokeHandlerOnNavigatingFromAsync(handler, navigationServiceNavigatingCancelEventArgs); if (!navigationServiceNavigatingCancelEventArgs.Cancel) { _alreadyPerformedOnNavigatingFrom = true; #if WINDOWS_PHONE || WINDOWS_PHONE_81 Dispatcher.BeginInvoke(() => { var frame = this.GetVisualAncestor<Frame>(); switch (e.NavigationMode) { case NavigationMode.New: frame.Navigate(e.Uri); break; #else await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { var frame = this.Frame; switch (e.NavigationMode) { case NavigationMode.New: frame.Navigate(e.SourcePageType, e.Parameter, e.NavigationTransitionInfo); break; #endif case NavigationMode.Back: frame.GoBack(); break; case NavigationMode.Forward: frame.GoForward(); break; } }); } } } }
/// <summary> /// Invokes the <see cref="IHandleNavigatingFrom.OnNavigatingFromAsync"/> for the current <see cref="FrameworkElement.DataContext"/>. /// </summary> /// <param name="handler">The <see cref="IHandleNavigatingFrom"/> instance.</param> /// <param name="e">An object that contains the event data.</param> /// <returns>The <see cref="Task"/> object representing the asynchronous operation.</returns> protected virtual Task InvokeHandlerOnNavigatingFromAsync(IHandleNavigatingFrom handler, NavigationServiceNavigatingCancelEventArgs e) => handler.OnNavigatingFromAsync(e);
/// <summary> /// Invokes the <see cref="IHandleNavigatingFrom.OnNavigatingFromAsync"/> for the current <see cref="FrameworkElement.DataContext"/>. /// </summary> /// <param name="handler">The <see cref="IHandleNavigatingFrom"/> instance.</param> /// <param name="e">An object that contains the event data.</param> /// <returns>The <see cref="Task"/> object representing the asynchronous operation.</returns> protected virtual Task InvokeHandlerOnNavigatingFromAsync(IHandleNavigatingFrom handler, NavigationServiceNavigatingCancelEventArgs e) => handler.OnNavigatingFromAsync(e);