예제 #1
0
파일: Frame.cs 프로젝트: jokm1/uno-2
        private bool InnerNavigate(PageStackEntry entry, NavigationMode mode)
        {
            try
            {
                // Navigating
                var navigatingFromArgs = new NavigatingCancelEventArgs(
                    mode,
                    entry.NavigationTransitionInfo,
                    entry.Parameter,
                    entry.SourcePageType
                    );

                Navigating?.Invoke(this, navigatingFromArgs);

                if (navigatingFromArgs.Cancel)
                {
                    // Frame canceled
                    OnNavigationStopped(entry, mode);
                    return(false);
                }

                CurrentEntry?.Instance.OnNavigatingFrom(navigatingFromArgs);

                if (navigatingFromArgs.Cancel)
                {
                    // Page canceled
                    OnNavigationStopped(entry, mode);
                    return(false);
                }

                // Navigate
                var previousEntry = CurrentEntry;
                CurrentEntry = entry;

                if (mode == NavigationMode.New)
                {
                    // Doing this first allows CurrentEntry to reuse existing page if pooling is enabled
                    ReleasePages(ForwardStack);
                }

                if (CurrentEntry.Instance == null)
                {
                    var page = CreatePageInstanceCached(entry.SourcePageType);
                    if (page == null)
                    {
                        return(false);
                    }

                    page.Frame            = this;
                    CurrentEntry.Instance = page;
                }

                Content = CurrentEntry.Instance;

                if (IsNavigationStackEnabled)
                {
                    switch (mode)
                    {
                    case NavigationMode.New:
                        ForwardStack.Clear();
                        if (previousEntry != null)
                        {
                            BackStack.Add(previousEntry);
                        }
                        break;

                    case NavigationMode.Back:
                        ForwardStack.Add(previousEntry);
                        BackStack.Remove(CurrentEntry);
                        break;

                    case NavigationMode.Forward:
                        BackStack.Add(previousEntry);
                        ForwardStack.Remove(CurrentEntry);
                        break;

                    case NavigationMode.Refresh:
                        break;
                    }
                }

                // Navigated
                var navigationEvent = new NavigationEventArgs(
                    CurrentEntry.Instance,
                    mode,
                    entry.NavigationTransitionInfo,
                    entry.Parameter,
                    entry.SourcePageType,
                    null
                    );

                previousEntry?.Instance.OnNavigatedFrom(navigationEvent);
                CurrentEntry.Instance.OnNavigatedTo(navigationEvent);
                Navigated?.Invoke(this, navigationEvent);

                VisualTreeHelper.CloseAllPopups();

                return(true);
            }
            catch (Exception exception)
            {
                NavigationFailed?.Invoke(this, new NavigationFailedEventArgs(entry.SourcePageType, exception));

                if (NavigationFailed == null)
                {
                    Application.Current.RaiseRecoverableUnhandledException(new InvalidOperationException("Navigation failed", exception));
                }

                return(false);
            }
        }
예제 #2
0
        private bool InnerNavigate(PageStackEntry entry, NavigationMode mode)
        {
            try
            {
                // Navigating
                var navigatingFromArgs = new NavigatingCancelEventArgs(
                    mode,
                    entry.NavigationTransitionInfo,
                    entry.Parameter,
                    entry.SourcePageType
                    );

                Navigating?.Invoke(this, navigatingFromArgs);

                CurrentEntry?.Instance.OnNavigatingFrom(navigatingFromArgs);

                if (navigatingFromArgs.Cancel)
                {
                    NavigationStopped?.Invoke(this, new NavigationEventArgs(
                                                  entry.Instance,
                                                  mode,
                                                  entry.NavigationTransitionInfo,
                                                  entry.Parameter,
                                                  entry.SourcePageType,
                                                  null
                                                  ));
                    return(false);
                }

                // Navigate
                var previousEntry = CurrentEntry;
                CurrentEntry = entry;

                if (CurrentEntry.Instance == null)
                {
                    var page = CreatePageInstance(entry.SourcePageType);
                    if (page == null)
                    {
                        return(false);
                    }

                    page.Frame            = this;
                    CurrentEntry.Instance = page;
                }

                Content = CurrentEntry.Instance;

                switch (mode)
                {
                case NavigationMode.New:
                    ForwardStack.Clear();
                    if (previousEntry != null)
                    {
                        BackStack.Add(previousEntry);
                    }
                    break;

                case NavigationMode.Back:
                    ForwardStack.Add(previousEntry);
                    BackStack.Remove(CurrentEntry);
                    break;

                case NavigationMode.Forward:
                    BackStack.Add(previousEntry);
                    ForwardStack.Remove(CurrentEntry);
                    break;

                case NavigationMode.Refresh:
                    break;
                }

                // Navigated
                var navigationEvent = new NavigationEventArgs(
                    CurrentEntry.Instance,
                    mode,
                    entry.NavigationTransitionInfo,
                    entry.Parameter,
                    entry.SourcePageType,
                    null
                    );

                previousEntry?.Instance.OnNavigatedFrom(navigationEvent);
                CurrentEntry.Instance.OnNavigatedTo(navigationEvent);
                Navigated?.Invoke(this, navigationEvent);

                VisualTreeHelper.CloseAllPopups();

                return(true);
            }
            catch (Exception exception)
            {
                NavigationFailed?.Invoke(this, new NavigationFailedEventArgs(entry.SourcePageType, exception));
                return(false);
            }
        }