Provides data for the NavigationFailed event.
Inheritance: NavigationBaseEventArgs
コード例 #1
0
ファイル: ModernFrame.cs プロジェクト: gro-ove/actools
        private void SetNavigationFailedContent(Uri newValue, NavigationType navigationType, Exception e) {
            Logging.Warning("Navigation failed: " + e?.InnerException);

            // raise failed event
            var failedArgs = new NavigationFailedEventArgs {
                Frame = this,
                Source = newValue,
                Error = e?.InnerException,
                Handled = false
            };

            OnNavigationFailed(failedArgs);

            // if not handled, show error as content
            var newContent = failedArgs.Handled ? null : failedArgs.Error;
            SetContent(newValue, navigationType, newContent, true);
        }
コード例 #2
0
ファイル: ModernFrame.cs プロジェクト: gro-ove/actools
 private void OnNavigationFailed(NavigationFailedEventArgs e) {
     NavigationFailed?.Invoke(this, e);
 }
コード例 #3
0
ファイル: ModernFrame.cs プロジェクト: gro-ove/actools
        private void NavigateSync(Uri oldValue, Uri newValue, NavigationType navigationType) {
            Debug.WriteLine("Navigating from '{0}' to '{1}'", oldValue, newValue);

            // set IsLoadingContent state
            SetValue(IsLoadingContentPropertyKey, true);

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

            // push previous source onto the history stack (only for new navigation types)
            if (oldValue != null) {
                switch (navigationType) {
                    case NavigationType.New:
                        _history.Push(oldValue);
                        _future.Clear();
                        break;
                    case NavigationType.Back:
                        _future.Push(oldValue);
                        break;
                    case NavigationType.Forward:
                        _history.Push(oldValue);
                        break;
                }
            }

            object newContent = null;

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

                if (navigationType == NavigationType.Refresh || !_contentCache.TryGetValue(newValueNoFragment, out newContent)) {
#if !DEBUG
                    try {
#endif
                    newContent = ContentLoader.LoadContent(newValue);

                    if (ShouldKeepContentAlive(newContent)) {
                        // keep the new content in memory
                        Debug.WriteLine("KEEP CONTENT ALIVE: " + newValue);
                        _contentCache[newValueNoFragment] = newContent;
                    }

                    SetContent(newValue, navigationType, newContent, false);
#if !DEBUG
                    } catch (Exception e) {
                        // raise failed event
                        var failedArgs = new NavigationFailedEventArgs {
                            Frame = this,
                            Source = newValue,
                            Error = e?.InnerException,
                            Handled = false
                        };

                        OnNavigationFailed(failedArgs);

                        // if not handled, show error as content
                        newContent = failedArgs.Handled ? null : failedArgs.Error;

                        SetContent(newValue, navigationType, newContent, true);
                    }
#endif
                }
            }

            // newValue is null or newContent was found in the cache
            SetContent(newValue, navigationType, newContent, false);
        }
コード例 #4
0
 private void Frame_NavigationFailed(object sender, NavigationFailedEventArgs e)
 {
 }
コード例 #5
0
		private void OnNavigationFailed(NavigationFailedEventArgs e)
		{
			if (NavigationFailed != null)
			{
				NavigationFailed(this, e);
			}
		}
コード例 #6
0
		private void Navigate(Uri oldValue, Uri newValue, NavigationType navigationType)
		{
			Debug.WriteLine("Navigating from '{0}' to '{1}'", oldValue, newValue);

			// set IsLoadingContent state
			SetValue(IsLoadingContentPropertyKey, true);

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

			// push previous source onto the history stack (only for new navigation types)
			if (oldValue != null && navigationType == NavigationType.New)
			{
				this.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();
					this.tokenSource = localTokenSource;
					// load the content (asynchronous!)
					var scheduler = TaskScheduler.FromCurrentSynchronizationContext();
					var task = this.ContentLoader.LoadContentAsync(newValue, this.tokenSource.Token);

					task.ContinueWith(t =>
					{
						try
						{
							if (t.IsCanceled || localTokenSource.IsCancellationRequested)
							{
								Debug.WriteLine("Cancelled navigation to '{0}'", newValue);
							}
							else if (t.IsFaulted)
							{
								// raise failed event
								var failedArgs = new NavigationFailedEventArgs
								{
									Frame = this,
									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);
							}
							else
							{
								newContent = t.Result;
								if (ShouldKeepContentAlive(newContent))
								{
									// keep the new content in memory
									this.contentCache[newValueNoFragment] = newContent;
								}

								SetContent(newValue, navigationType, newContent, false);
							}
						}
						finally
						{
							// clear global tokenSource to avoid a Cancel on a disposed object
							if (this.tokenSource == localTokenSource)
							{
								this.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);
		}
コード例 #7
0
 private void Frame_NavigationFailed(object sender, NavigationFailedEventArgs e)
 {
     LogMessage("NavigationFailed: {0}\r\n", e.Error.Message);
 }