예제 #1
0
        /// <summary>
        /// Called when the <c>Navigated</c> event is invoked.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="NavigationEventArgs"/> instance containing the event data.</param>
        /// <remarks>
        /// This method is public due to the fact that weak events are used. Otherwise, the navigation completed events
        /// could not be handled (because we unsubscribed from the _rootFrame) when navigating away to prevent memory
        /// leaks.
        /// <para />
        /// Please, do not call this method yourself, otherwise you can seriously ruin your apps.
        /// </remarks>
        public void OnNavigatedEvent(object sender, NavigationEventArgs e)
        {
            if (!CanHandleNavigation)
            {
                return;
            }

            var uriString = e.GetUriWithoutQueryInfo();

            // If this navigation event is not meant for this page, exit
            if (!e.IsNavigationForView(TargetControlType))
            {
                return;
            }

            HasHandledSaveAndCancelLogic = false;

            if (_hasNavigatedButNotNavigatedAway)
            {
                return;
            }

            _hasNavigatedButNotNavigatedAway = true;

            if (e.Uri != null && e.Uri.ToString().Contains("app://external"))
            {
                Log.Debug("Navigating away from the application, ignoring navigation");
                return;
            }

            OnNavigated(e);

#if NETFX_CORE
            var navigationContext = e.Parameter;
#elif WINDOWS_PHONE
            var navigationContext = ((PhoneApplicationPage)TargetControl).NavigationContext;
#elif SILVERLIGHT
            var navigationContext = e.Content;
#else
            var navigationContext = e.ExtraData;
#endif

            HandleNavigated(navigationContext);
        }