Пример #1
0
        /// <summary>
        /// Navigates to the specified route on the route's router depth with an optional argument.
        /// </summary>
        /// <param name="route">The destination route to navigate to.</param>
        /// <param name="argument">The optional argument to pass to the page (null by default).</param>
        public void NavigateTo(Route route, object?argument = null)
        {
            // Fire off the navigation started event
            var navigationStartedEventArgs = new RouterNavigationCancelEventArgs(route);

            NavigationStarted?.Invoke(this, navigationStartedEventArgs);

            // Cancel the navigation if the event was handled to do so
            if (navigationStartedEventArgs.Cancel)
            {
                NavigationCanceled?.Invoke(this, new RouterNavigationEventArgs(route));
                return;
            }

            // If the specified route doesn't exist or it's already active, raise the navigation error event and cancel the navigation
            if (!mRoutes.Contains(route))
            {
                NavigationError?.Invoke(this, new RouterNavigationErrorEventArgs(route, RouterNavigationError.NonExistingRoute));
                return;
            }
            else if (mActiveRoutes[route.Depth] == route)
            {
                NavigationError?.Invoke(this, new RouterNavigationErrorEventArgs(route, RouterNavigationError.RouteAlreadyActive));
                return;
            }

            // Otherwise set the destination route's argument and make it the active route on its depth
            route.Argument             = argument;
            mActiveRoutes[route.Depth] = route;

            // Raise the navigation completed event as navigation was successful
            NavigationCompleted?.Invoke(this, new RouterNavigationEventArgs(route));
        }
Пример #2
0
 private void NavigationCanceledByUser(NavigationCanceled _)
 {
     // Prevent hijacking of Navigation in OnNavigatedTo--the user canceled the previous navigation.
     this._pinnedFavoriteClicked = null;
     this._pinnedFavoritesList   = null;
 }