public LoadResult EndLoad(IAsyncResult asyncResult) { var result = asyncResult as AssemblyNavigationContentLoaderAsyncResult; if (result == null) { throw new InvalidOperationException(string.Format("Wrong kind of {0} passed in. The {0} passed in should only come from {1}.", "IAsyncResult", "AssemblyNavigationContentLoader.BeginLoad")); } var loadResult = new LoadResult(result.GetResultInstance()); return loadResult; }
private void ContentLoader_BeginLoad_Callback(IAsyncResult result) { DependencyObject content = null; Uri uriBeingLoaded = null; try { NavigationOperation asyncNavigationOperationCompleted = result.AsyncState as NavigationOperation; NavigationOperation navOp = this._currentNavigation; if (navOp == null || navOp.Uri != asyncNavigationOperationCompleted.Uri) { // We already fired NavigationStopped in NavigateCore(), so just return without doing anything return; } uriBeingLoaded = navOp.UriBeforeMapping; LoadResult loadResult = this._contentLoader.EndLoad(result); if (loadResult == null) { throw new InvalidOperationException(String.Format(Resource.NavigationService_InvalidLoadResult, "LoadResult", this._contentLoader.GetType())); } else if (loadResult.RedirectUri != null) { // If we get a Redirect, navigate again without storing any context this.NavigateCore(loadResult.RedirectUri, NavigationMode.New, false /*suppressJournalAdd*/, true /*isRedirect*/); } else { content = loadResult.LoadedContent as DependencyObject; // If the content is anything but a UserControl, we should throw. // We support UserControls as they are a typical thing created in designers such as Blend, // but for a full experience one would use Page to get to things like NavigationContext, // NavigationService, Title, etc. if (!(content is UserControl)) { throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, Resource.NavigationService_ContentIsNotAUserControl, content == null ? "null" : content.GetType().ToString(), "System.Windows.Controls.UserControl")); } // Content loader was successful, so complete navigation // Create a new navigation context JournalEntry.SetNavigationContext(content, new NavigationContext(UriParsingHelper.InternalUriParseQueryStringToDictionary(asyncNavigationOperationCompleted.Uri, true /* decodeResults */))); content.SetValue(NavigationServiceProperty, this); // Complete navigation operation this.CompleteNavigation(content); } } catch (Exception ex) { if (this.RaiseNavigationFailed(uriBeingLoaded, ex)) { throw; } } }