Exemple #1
0
        protected override async Task InnerNavigateBack(NavigationStackEntry entryToRemove, NavigationStackEntry activeEntry)
        {
            // When this flag is true, the Frame already navigated back (e.g. using the back button),
            // so we don't need to ask the Frame to navigate back. The only thing we need to make
            // sure is to reset the DataContext of the view.
            if (!_isProcessingFrameInitiatedBack)
            {
                await Dispatcher.RunTaskAsync(CoreDispatcherPriority.High, UIBack);

                if (!(entryToRemove.Request.SuppressTransitions ?? false))
                {
                    // There's no way to know when the animation ends. So, we assume it runs for 250ms.
                    await Task.Delay(millisecondsDelay : 250);
                }
            }

            _ = Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => UIResetDataContext(entryToRemove));

            async Task UIBack()
            {
                try
                {
                    var overrideInfo = entryToRemove.Request.SuppressTransitions ?? false
                                                ? (NavigationTransitionInfo) new SuppressNavigationTransitionInfo()
                                                : (NavigationTransitionInfo) new SlideNavigationTransitionInfo()
                    {
                        Effect = SlideNavigationTransitionEffect.FromRight
                    };

                    var result = await WaitForNavigationResult(() => _frame.GoBack(overrideInfo));

#if NETFX_CORE
                    // On Windows, Frame re-creates a new Page instance for every navigation (whether through Navigate or GoBack),
                    // unless NavigationCacheMode is set to Required (in which case a single Page instance is recycled).
                    if (result.Content != activeEntry.View)
                    {
                        // A new Page instance has been created and set as the content of the Frame.
                        // However, this new instance doesn't reflect the state or DataContext of the actual previous page.
                        // Therefore, we replace it with the previous page instance we saved earlier.
                        _frame.Content = activeEntry.View;
                    }
#endif
                }
                catch (Exception e)
                {
                    if (_logger.IsEnabled(LogLevel.Error))
                    {
                        _logger.LogError($"Failed frame navigate back.", e);
                    }
                }
            }
        }
Exemple #2
0
 protected override Task InnerNavigateBack(NavigationStackEntry entryToRemove, NavigationStackEntry activeEntry)
 {
     // Don't do anything.
     return(Task.CompletedTask);
 }