RemoveFragment() public static méthode

Removes the fragment from specified uri and return it.
public static RemoveFragment ( Uri uri ) : Uri
uri System.Uri The uri
Résultat System.Uri
Exemple #1
0
        /// <summary>
        /// Performs navigation against current ModernFrame.
        /// </summary>
        /// <param name="oldValue">Navigate From Uri</param>
        /// <param name="newValue">Navigate To Uri</param>
        /// <remarks>
        /// Can be used to fire Navigated events.
        /// </remarks>
        public void Navigate(Uri oldValue, Uri newValue)
        {
            // if resetting source or old source equals new, don't do anything
            if (Frame.IsResetSource || newValue != null && newValue.Equals(oldValue))
            {
                return;
            }

            // handle fragment navigation
            string newFragment        = null;
            var    oldValueNoFragment = NavigationHelper.RemoveFragment(oldValue);
            var    newValueNoFragment = NavigationHelper.RemoveFragment(newValue, out newFragment);

            if (newValueNoFragment != null && newValueNoFragment.Equals(oldValueNoFragment))
            {
                // fragment navigation
                var args = new FragmentNavigationEventArgs
                {
                    Fragment = newFragment
                };
                OnFragmentNavigation(Frame.Content as IContent, args);
            }
            else
            {
                var navType = Frame.IsNavigatingHistory ? NavigationType.Back : NavigationType.New;

                // only invoke CanNavigate for new navigation
                if (!CanNavigate(oldValue, newValue, navType))
                {
                    return;
                }

                Navigate(oldValue, newValue, navType);
            }
        }
Exemple #2
0
        private void SetContent <TK>(Uri newSource, NavigationType navigationType, object newContent, bool contentIsError, TK passingParameter)
        {
            // assign content
            Frame.Content = newContent;
            // do not raise navigated event when error
            if (!contentIsError)
            {
                var args = new ParameterNavigationEventArgs <TK>
                {
                    Frame          = Frame,
                    Source         = newSource,
                    Content        = newContent,
                    NavigationType = navigationType,
                    Parameter      = passingParameter
                };

                OnNavigated(Frame.Content, newContent, args);

                OnParameterNavigation(newContent, args);
            }
            // set IsLoadingContent to false
            Frame.SetValue(ModernFrame.IsLoadingContentPropertyKey, false);

            if (contentIsError)
            {
                return;
            }

            // and raise optional fragment navigation events
            string fragment;

            NavigationHelper.RemoveFragment(newSource, out fragment);

            if (fragment == null)
            {
                return;
            }

            // fragment navigation
            var fragmentArgs = new FragmentNavigationEventArgs
            {
                Fragment = fragment
            };

            OnFragmentNavigation(newContent, fragmentArgs);
        }
Exemple #3
0
        /// <summary>
        /// Performs navigation against current ModernFrame.
        /// </summary>
        /// <param name="oldValue">Navigate From Uri</param>
        /// <param name="newValue">Navigate To Uri</param>
        /// <param name="navigationType">Type of Navigation</param>
        /// <param name="passingParameter">Parameter for passing.</param>
        /// <remarks>
        /// Can be used to fire Navigated events.
        /// </remarks>
        public void Navigate <TK>(Uri oldValue, Uri newValue, NavigationType navigationType, TK passingParameter)
        {
            Debug.WriteLine("Navigating from '{0}' to '{1}'", oldValue, newValue);

            // set IsLoadingContent state
            Frame.SetValue(ModernFrame.IsLoadingContentPropertyKey, true);

            // cancel previous load content task (if any)
            // note: no need for thread synchronization, this code always executes on the UI thread
            if (Frame.TokenSource != null)
            {
                Frame.TokenSource.Cancel();
                Frame.TokenSource = null;
            }

            // push previous source onto the history stack (only for new navigation types)
            if (oldValue != null && navigationType == NavigationType.New)
            {
                _history.Push(oldValue);
            }

            object newContent = null;

            if (newValue != null)
            {
                // content is cached on uri without fragment
                var newValueNoFragment = NavigationHelper.RemoveFragment(newValue);

                if (navigationType == NavigationType.Refresh || !this._contentCache.TryGetValue(newValueNoFragment, out newContent))
                {
                    var localTokenSource = new CancellationTokenSource();
                    Frame.TokenSource = localTokenSource;
                    // load the content (asynchronous!)
                    var scheduler = TaskScheduler.FromCurrentSynchronizationContext();

                    var task = Frame.ContentLoader.LoadContentAsync(newValue, Frame.TokenSource.Token);

                    task.ContinueWith(t => {
                        try
                        {
                            if (t.IsCanceled || localTokenSource.IsCancellationRequested)
                            {
                                Debug.WriteLine("Cancelled navigation to '{0}'", newValue);
                            }
                            else if (t.IsFaulted && t.Exception != null)
                            {
                                var failedArgs = new NavigationFailedEventArgs
                                {
                                    Frame   = Frame,
                                    Source  = newValue,
                                    Error   = t.Exception.InnerException,
                                    Handled = false
                                };

                                OnNavigationFailed(failedArgs);
                                // if not handled, show error as content
                                newContent = failedArgs.Handled ? null : failedArgs.Error;
                                SetContent(newValue, navigationType, newContent, true, passingParameter);
                            }
                            else
                            {
                                newContent = t.Result;

                                if (ShouldKeepContentAlive(newContent))
                                {
                                    // keep the new content in memory
                                    _contentCache[newValueNoFragment] = newContent;
                                }

                                SetContent(newValue, navigationType, newContent, false, passingParameter);
                            }
                        }
                        finally
                        {
                            // clear global tokenSource to avoid a Cancel on a disposed object
                            if (Frame.TokenSource == localTokenSource)
                            {
                                Frame.TokenSource = null;
                            }

                            // and dispose of the local tokensource
                            localTokenSource.Dispose();
                        }
                    }, scheduler);
                    return;
                }
            }

            // newValue is null or newContent was found in the cache
            SetContent(newValue, navigationType, newContent, false, passingParameter);
        }