public async Task NavigateFromCurrentViewModel_Calls_VieModel_OnNavigatedFrom() { await ExecuteOnUIThread(() => { var frame = new FrameFacadeAdapter(new Frame()); bool viewModelNavigatedFromCalled = false; var viewModel = new MockPageViewModel(); viewModel.OnNavigatedFromCommand = (frameState, suspending) => { Assert.IsFalse(suspending); viewModelNavigatedFromCalled = true; }; var sessionStateService = new MockSessionStateService(); sessionStateService.GetSessionStateForFrameDelegate = (currentFrame) => new Dictionary <string, object>(); var navigationService = new FrameNavigationService(frame, (pageToken) => typeof(MockPage), sessionStateService); // Initial navigatio navigationService.Navigate("page0", 0); // Set up the frame's content with a Page var view = new MockPage(); view.DataContext = viewModel; frame.Content = view; // Navigate to fire the NavigatedToCurrentViewModel navigationService.Navigate("page1", 1); Assert.IsTrue(viewModelNavigatedFromCalled); }); }
public async Task NavigateToCurrentViewModel_Calls_VieModel_OnNavigatedTo() { await ExecuteOnUIThread(() => { var frame = new FrameFacadeAdapter(new Frame()); bool viewModelNavigatedToCalled = false; var viewModel = new MockPageViewModel(); viewModel.OnNavigatedFromCommand = (a, b) => Assert.IsTrue(true); viewModel.OnNavigatedToCommand = (parameter, navigationMode, frameState) => { Assert.AreEqual(NavigationMode.New, navigationMode); viewModelNavigatedToCalled = true; }; // Set up the viewModel to the Page we navigated frame.Navigated += (sender, e) => { var view = frame.Content as FrameworkElement; view.DataContext = viewModel; }; var sessionStateService = new MockSessionStateService(); sessionStateService.GetSessionStateForFrameDelegate = (currentFrame) => new Dictionary<string, object>(); var navigationService = new FrameNavigationService(frame, (pageToken) => typeof(MockPage), sessionStateService); navigationService.Navigate("Mock", 1); Assert.IsTrue(viewModelNavigatedToCalled); }); }
protected override void OnApplyTemplate() { Frame = GetTemplateChild("PlayerFrame") as Frame; { var frameFacade = new FrameFacadeAdapter(Frame); var sessionStateService = new SessionStateService(); var ns = new FrameNavigationService(frameFacade , (pageToken) => { if (pageToken == nameof(Views.VideoPlayerPage)) { return(typeof(Views.VideoPlayerPage)); } else if (pageToken == nameof(Views.LivePlayerPage)) { return(typeof(Views.LivePlayerPage)); } else { return(typeof(Views.BlankPage)); } }, sessionStateService); (DataContext as ViewModels.MenuNavigatePageBaseViewModel).SetNavigationService(ns); } base.OnApplyTemplate(); }
public async Task Navigate_To_Page_With_UseTitleBarBackButton_False_Does_Not_Change_Back_Button_Visibility() { await DispatcherHelper.ExecuteOnUIThread(() => { var eventAggregator = new EventAggregator(); var frame = new FrameFacadeAdapter(new Frame()); var sessionStateService = new MockSessionStateService(); sessionStateService.GetSessionStateForFrameDelegate = (currentFrame) => new Dictionary <string, object>(); var navigationService = new FrameNavigationService(frame, (pageToken) => typeof(MockPage), sessionStateService); var deviceGestureService = new DeviceGestureService(eventAggregator); deviceGestureService.UseTitleBarBackButton = true; var navigationManager = SystemNavigationManager.GetForCurrentView(); // Reset back button visibility before running, can't do this in TestInitialize because CoreWindow sometimes isn't ready SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed; // If it's collapsed and we navigate, it stays collapsed Assert.AreEqual(AppViewBackButtonVisibility.Collapsed, navigationManager.AppViewBackButtonVisibility); navigationService.Navigate("Mock", 1); Assert.AreEqual(AppViewBackButtonVisibility.Collapsed, navigationManager.AppViewBackButtonVisibility); // If it's visible and our back stack is emptied, it stays visible navigationManager.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible; navigationService.ClearHistory(); Assert.AreEqual(AppViewBackButtonVisibility.Visible, navigationManager.AppViewBackButtonVisibility); }); }
public async Task GoBack_When_CanGoBack() { await ExecuteOnUIThread(() => { var frame = new FrameFacadeAdapter(new Frame()); var sessionStateService = new MockSessionStateService(); sessionStateService.GetSessionStateForFrameDelegate = (currentFrame) => new Dictionary <string, object>(); var navigationService = new FrameNavigationService(frame, (pageToken) => typeof(MockPage), sessionStateService); bool resultFirstNavigation = navigationService.Navigate("MockPage", 1); Assert.IsInstanceOfType(frame.Content, typeof(MockPage)); Assert.AreEqual(1, ((MockPage)frame.Content).PageParameter); Assert.IsFalse(navigationService.CanGoBack()); bool resultSecondNavigation = navigationService.Navigate("Mock", 2); Assert.IsInstanceOfType(frame.Content, typeof(MockPage)); Assert.AreEqual(2, ((MockPage)frame.Content).PageParameter); Assert.IsTrue(navigationService.CanGoBack()); navigationService.GoBack(); Assert.IsInstanceOfType(frame.Content, typeof(MockPage)); Assert.AreEqual(1, ((MockPage)frame.Content).PageParameter); Assert.IsFalse(navigationService.CanGoBack()); }); }
public async Task Remove_All_Back_Button_Collapsed() { await DispatcherHelper.ExecuteOnUIThread(() => { var eventAggregator = new EventAggregator(); var frame = new FrameFacadeAdapter(new Frame(), eventAggregator); var sessionStateService = new MockSessionStateService(); sessionStateService.GetSessionStateForFrameDelegate = (currentFrame) => new Dictionary <string, object>(); var navigationService = new FrameNavigationService(frame, (pageToken) => typeof(MockPage), sessionStateService); var deviceGestureService = new DeviceGestureService(eventAggregator); deviceGestureService.UseTitleBarBackButton = true; var navigationManager = SystemNavigationManager.GetForCurrentView(); // Reset back button visibility before running, can't do this in TestInitialize because CoreWindow sometimes isn't ready SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed; Assert.AreEqual(AppViewBackButtonVisibility.Collapsed, navigationManager.AppViewBackButtonVisibility); navigationService.Navigate("Mock", 1); Assert.AreEqual(AppViewBackButtonVisibility.Collapsed, navigationManager.AppViewBackButtonVisibility); navigationService.Navigate("Mock", 2); Assert.AreEqual(AppViewBackButtonVisibility.Visible, navigationManager.AppViewBackButtonVisibility); navigationService.RemoveAllPages(); Assert.AreEqual(AppViewBackButtonVisibility.Collapsed, navigationManager.AppViewBackButtonVisibility); }); }
/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. The Parameter /// property provides the group to be displayed.</param> protected override void OnNavigatedTo(NavigationEventArgs e) { if (e == null) throw new ArgumentNullException("e"); // Returning to a cached page through navigation shouldn't trigger state loading if (this._pageKey != null) return; var frameFacade = new FrameFacadeAdapter(this.Frame); var frameState = GetSessionStateForFrame(frameFacade); this._pageKey = "Page-" + frameFacade.BackStackDepth; if (e.NavigationMode == NavigationMode.New) { // Clear existing state for forward navigation when adding a new page to the // navigation stack var nextPageKey = this._pageKey; int nextPageIndex = frameFacade.BackStackDepth; while (frameState.Remove(nextPageKey)) { nextPageIndex++; nextPageKey = "Page-" + nextPageIndex; } // Pass the navigation parameter to the new page this.LoadState(e.Parameter, null); } else { // Pass the navigation parameter and preserved page state to the page, using // the same strategy for loading suspended state and recreating pages discarded // from cache this.LoadState(e.Parameter, (Dictionary<String, Object>)frameState[this._pageKey]); } }
public async Task Navigate_Raises_NavigationStateChangedEvent() { var tcs = new TaskCompletionSource <bool>(); var eventAggregator = new EventAggregator(); eventAggregator.GetEvent <NavigationStateChangedEvent>().Subscribe((args) => tcs.SetResult(args.StateChange == StateChangeType.Forward)); await DispatcherHelper.ExecuteOnUIThread(() => { var frame = new FrameFacadeAdapter(new Frame(), eventAggregator); var sessionStateService = new MockSessionStateService(); sessionStateService.GetSessionStateForFrameDelegate = (currentFrame) => new Dictionary <string, object>(); var navigationService = new FrameNavigationService(frame, (pageToken) => typeof(MockPage), sessionStateService); navigationService.Navigate("Mock", 1); }); await Task.WhenAny(tcs.Task, Task.Delay(200)); if (tcs.Task.IsCompleted) { Assert.IsTrue(tcs.Task.Result); } else { Assert.Fail("NavigationStateChangedEvent event wasn't raised within 200 ms."); } }
/// <summary> /// Initializes the Frame and its content. /// </summary> /// <param name="args">The <see cref="IActivatedEventArgs"/> instance containing the event data.</param> /// <returns>A task of a Frame that holds the app content.</returns> protected async Task <Frame> InitializeFrameAsync(IActivatedEventArgs args) { // Create a Frame to act as the navigation context and navigate to the first page var rootFrame = new Frame(); if (ExtendedSplashScreenFactory != null) { Page extendedSplashScreen = this.ExtendedSplashScreenFactory.Invoke(args.SplashScreen); rootFrame.Content = extendedSplashScreen; } rootFrame.Navigated += OnNavigated; var frameFacade = new FrameFacadeAdapter(rootFrame); //Initialize PrismApplication common services SessionStateService = new SessionStateService(); //Configure VisualStateAwarePage with the ability to get the session state for its frame VisualStateAwarePage.GetSessionStateForFrame = frame => SessionStateService.GetSessionStateForFrame(frameFacade); //Associate the frame with a key SessionStateService.RegisterFrame(frameFacade, "AppFrame"); NavigationService = CreateNavigationService(frameFacade, SessionStateService); DeviceGestureService = CreateDeviceGestureService(); DeviceGestureService.GoBackRequested += OnGoBackRequested; DeviceGestureService.GoForwardRequested += OnGoForwardRequested; // Set a factory for the ViewModelLocator to use the default resolution mechanism to construct view models ViewModelLocationProvider.SetDefaultViewModelFactory(Resolve); OnRegisterKnownTypesForSerialization(); if (args.PreviousExecutionState == ApplicationExecutionState.Terminated) { await SessionStateService.RestoreSessionStateAsync(); } await OnInitializeAsync(args); if (args.PreviousExecutionState == ApplicationExecutionState.Terminated) { // Restore the saved session state and navigate to the last page visited try { SessionStateService.RestoreFrameState(); NavigationService.RestoreSavedNavigation(); _isRestoringFromTermination = true; } catch (SessionStateServiceException) { // Something went wrong restoring state. // Assume there is no state and continue } } return(rootFrame); }
public async Task Set_State_Raises_NavigationStateChangedEvent() { var tcs = new TaskCompletionSource <bool>(); var eventAggregator = new EventAggregator(); eventAggregator.GetEvent <NavigationStateChangedEvent>().Subscribe((args) => tcs.SetResult(true)); await DispatcherHelper.ExecuteOnUIThread(() => { var frame = new FrameFacadeAdapter(new Frame(), eventAggregator); frame.SetNavigationState("1,0"); }); await Task.WhenAny(tcs.Task, Task.Delay(200)); if (tcs.Task.IsCompleted) { Assert.IsTrue(tcs.Task.Result); } else { Assert.Fail("NavigationStateChangedEvent event wasn't raised within 200 ms."); } }
public static async Task <PlayerWindowManager> CreatePlayerWindowManager(CoreApplicationView playerView) { INavigationService ns = null; int id = 0; await playerView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { var frame = new Frame(); var frameFacade = new FrameFacadeAdapter(frame); Window.Current.Content = frame; var sessionStateService = new SessionStateService(); ns = new FrameNavigationService(frameFacade , (pageToken) => { if (pageToken == nameof(Views.VideoPlayerControl)) { return(typeof(Views.VideoPlayerControl)); } else { return(typeof(Page)); } }, sessionStateService); id = ApplicationView.GetApplicationViewIdForWindow(playerView.CoreWindow); }); return(new PlayerWindowManager(playerView, id, ns)); }
public async Task RestoreSavedNavigation_ClearsOldForwardNavigation() { await ExecuteOnUIThread(() => { var frame = new FrameFacadeAdapter(new Frame()); var sessionStateService = new MockSessionStateService(); var frameSessionState = new Dictionary <string, object>(); sessionStateService.GetSessionStateForFrameDelegate = (currentFrame) => frameSessionState; var navigationService = new FrameNavigationService(frame, (pageToken) => typeof(MockPageWithViewModel), sessionStateService); navigationService.Navigate("Page1", 1); Assert.AreEqual(1, frameSessionState.Count, "VM 1 state only"); navigationService.Navigate("Page2", 2); Assert.AreEqual(2, frameSessionState.Count, "VM 1 and 2"); navigationService.Navigate("Page3", 3); Assert.AreEqual(3, frameSessionState.Count, "VM 1, 2, and 3"); navigationService.GoBack(); Assert.AreEqual(2, ((Dictionary <string, object>)frameSessionState["ViewModel-2"]).Count); Assert.AreEqual(3, frameSessionState.Count, "VM 1, 2, and 3"); navigationService.Navigate("Page4", 4); Assert.AreEqual(0, ((Dictionary <string, object>)frameSessionState["ViewModel-2"]).Count); Assert.AreEqual(3, frameSessionState.Count, "VM 1, 2, and 4"); }); }
public async Task NavigateToCurrentViewModel_Calls_VieModel_OnNavigatedTo() { await ExecuteOnUIThread(() => { var frame = new FrameFacadeAdapter(new Frame()); bool viewModelNavigatedToCalled = false; var viewModel = new MockPageViewModel(); viewModel.OnNavigatedFromCommand = (a, b) => Assert.IsTrue(true); viewModel.OnNavigatedToCommand = (parameter, navigationMode, frameState) => { Assert.AreEqual(NavigationMode.New, navigationMode); viewModelNavigatedToCalled = true; }; // Set up the viewModel to the Page we navigated frame.Navigated += (sender, e) => { var view = frame.Content as FrameworkElement; view.DataContext = viewModel; }; var sessionStateService = new MockSessionStateService(); sessionStateService.GetSessionStateForFrameDelegate = (currentFrame) => new Dictionary <string, object>(); var navigationService = new FrameNavigationService(frame, (pageToken) => typeof(MockPage), sessionStateService); navigationService.Navigate("Mock", 1); Assert.IsTrue(viewModelNavigatedToCalled); }); }
/// <summary> /// Invoked when this page will no longer be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. The Parameter /// property provides the group to be displayed.</param> protected override void OnNavigatedFrom(NavigationEventArgs e) { var frameFacade = new FrameFacadeAdapter(this.Frame); var frameState = GetSessionStateForFrame(frameFacade); var pageState = new Dictionary<String, Object>(); this.SaveState(pageState); frameState[_pageKey] = pageState; }
public async Task Navigate_To_Invalid_Page() { await ExecuteOnUIThread(() => { var frame = new FrameFacadeAdapter(new Frame()); var sessionStateService = new MockSessionStateService(); sessionStateService.GetSessionStateForFrameDelegate = (currentFrame) => new Dictionary<string, object>(); var navigationService = new FrameNavigationService(frame, (pageToken) => typeof(string), sessionStateService); bool result = navigationService.Navigate("Mock", 1); Assert.IsFalse(result); Assert.IsNull(frame.Content); }); }
public async Task Navigate_To_Invalid_Page() { await ExecuteOnUIThread(() => { var frame = new FrameFacadeAdapter(new Frame()); var sessionStateService = new MockSessionStateService(); sessionStateService.GetSessionStateForFrameDelegate = (currentFrame) => new Dictionary <string, object>(); var navigationService = new FrameNavigationService(frame, (pageToken) => typeof(string), sessionStateService); bool result = navigationService.Navigate("Mock", 1); Assert.IsFalse(result); Assert.IsNull(frame.Content); }); }
public async Task PageTokenThatCannotBeResolved_ThrowsMeaningfulException() { await ExecuteOnUIThread(() => { var frame = new FrameFacadeAdapter(new Frame()); var sessionStateService = new MockSessionStateService(); var frameSessionState = new Dictionary <string, object>(); sessionStateService.GetSessionStateForFrameDelegate = (currentFrame) => frameSessionState; Func <string, Type> unresolvablePageTokenReturnsNull = pageToken => null; var navigationService = new FrameNavigationService(frame, unresolvablePageTokenReturnsNull, sessionStateService); Assert.ThrowsException <ArgumentException>( () => navigationService.Navigate("anything", 1) ); }); }
public async Task Navigate_To_Valid_Page() { await ExecuteOnUIThread(() => { var frame = new FrameFacadeAdapter(new Frame()); var sessionStateService = new MockSessionStateService(); sessionStateService.GetSessionStateForFrameDelegate = (currentFrame) => new Dictionary <string, object>(); var navigationService = new FrameNavigationService(frame, (pageToken) => typeof(MockPage), sessionStateService); bool result = navigationService.Navigate("Mock", 1); Assert.IsTrue(result); Assert.IsNotNull(frame.Content); Assert.IsInstanceOfType(frame.Content, typeof(MockPage)); Assert.AreEqual(1, ((MockPage)frame.Content).PageParameter); }); }
public async Task Navigate_To_Valid_Page() { await ExecuteOnUIThread(() => { var frame = new FrameFacadeAdapter(new Frame()); var sessionStateService = new MockSessionStateService(); sessionStateService.GetSessionStateForFrameDelegate = (currentFrame) => new Dictionary<string, object>(); var navigationService = new FrameNavigationService(frame, (pageToken) => typeof(MockPage), sessionStateService); bool result = navigationService.Navigate("Mock", 1); Assert.IsTrue(result); Assert.IsNotNull(frame.Content); Assert.IsInstanceOfType(frame.Content, typeof(MockPage)); Assert.AreEqual(1, ((MockPage)frame.Content).PageParameter); }); }
public async Task Navigate_To_Page_With_Null_Aggregator_Still_Works() { await DispatcherHelper.ExecuteOnUIThread(() => { var frame = new FrameFacadeAdapter(new Frame()); var sessionStateService = new MockSessionStateService(); sessionStateService.GetSessionStateForFrameDelegate = (currentFrame) => new Dictionary <string, object>(); var navigationService = new FrameNavigationService(frame, (pageToken) => typeof(MockPage), sessionStateService); var navigationManager = SystemNavigationManager.GetForCurrentView(); // Reset back button visibility before running, can't do this in TestInitialize because CoreWindow sometimes isn't ready SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed; bool result = navigationService.Navigate("Mock", 1); Assert.IsTrue(result); }); }
public async Task Resuming_Calls_ViewModel_OnNavigatedTo() { await ExecuteOnUIThread(() => { var frame = new FrameFacadeAdapter(new Frame()); var sessionStateService = new MockSessionStateService(); sessionStateService.GetSessionStateForFrameDelegate = (currentFrame) => new Dictionary <string, object>(); var navigationService = new FrameNavigationService(frame, (pageToken) => typeof(MockPage), sessionStateService); navigationService.Navigate("Mock", 1); var viewModel = new MockPageViewModel(); viewModel.OnNavigatedToCommand = (navigationParameter, navigationMode, frameState) => { Assert.AreEqual(NavigationMode.Refresh, navigationMode); }; var page = (MockPage)frame.Content; page.DataContext = viewModel; navigationService.RestoreSavedNavigation(); }); }
public async Task Suspending_Calls_VieModel_OnNavigatedFrom() { await ExecuteOnUIThread(() => { var frame = new FrameFacadeAdapter(new Frame()); var sessionStateService = new MockSessionStateService(); sessionStateService.GetSessionStateForFrameDelegate = (currentFrame) => new Dictionary <string, object>(); var navigationService = new FrameNavigationService(frame, (pageToken) => typeof(MockPage), sessionStateService); navigationService.Navigate("Mock", 1); var viewModel = new MockPageViewModel(); viewModel.OnNavigatedFromCommand = (frameState, suspending) => { Assert.IsTrue(suspending); }; var page = (MockPage)frame.Content; page.DataContext = viewModel; navigationService.Suspending(); }); }
public async Task ViewModelOnNavigatedFromCalled_WithItsOwnStateDictionary() { await ExecuteOnUIThread(() => { var frame = new FrameFacadeAdapter(new Frame()); var sessionStateService = new MockSessionStateService(); var frameSessionState = new Dictionary <string, object>(); sessionStateService.GetSessionStateForFrameDelegate = (currentFrame) => frameSessionState; var navigationService = new FrameNavigationService(frame, (pageToken) => typeof(MockPageWithViewModel), sessionStateService); navigationService.Navigate("Page1", 1); Assert.AreEqual(1, frameSessionState.Count, "VM 1 state only"); navigationService.Navigate("Page2", 2); Assert.AreEqual(2, frameSessionState.Count, "VM 1 and 2"); navigationService.Navigate("Page1", 1); Assert.AreEqual(3, frameSessionState.Count, "VM 1, 2, and 1 again."); navigationService.Navigate("Page3", 3); Assert.AreEqual(4, frameSessionState.Count, "VM 1, 2, 1, and 3"); }); }
protected override UIElement CreateShell(Frame rootFrame) { rootFrame.CacheSize = 5; rootFrame.NavigationFailed += (_, e) => { Debug.WriteLine("Page navigation failed!!"); Debug.WriteLine(e.SourcePageType.AssemblyQualifiedName); Debug.WriteLine(e.Exception.ToString()); _ = OutputErrorFile(e.Exception, e.SourcePageType?.AssemblyQualifiedName); }; // Grid // |- HohoemaInAppNotification // |- PlayerWithPageContainerViewModel // | |- MenuNavigatePageBaseViewModel // | |- rootFrame var menuPageBase = new Views.MenuNavigatePageBase() { Content = rootFrame, DataContext = Container.Resolve <ViewModels.MenuNavigatePageBaseViewModel>() }; Views.PlayerWithPageContainer playerWithPageContainer = new Views.PlayerWithPageContainer() { Content = menuPageBase, DataContext = Container.Resolve <ViewModels.PlayerWithPageContainerViewModel>() }; playerWithPageContainer.ObserveDependencyProperty(Views.PlayerWithPageContainer.FrameProperty) .Where(x => x != null) .Take(1) .Subscribe(async frame => { var frameFacade = new FrameFacadeAdapter(playerWithPageContainer.Frame, EventAggregator); var sessionStateService = new SessionStateService(); var ns = new FrameNavigationService(frameFacade , (pageToken) => { if (pageToken == nameof(Views.VideoPlayerPage)) { return(typeof(Views.VideoPlayerPage)); } else if (pageToken == nameof(Views.LivePlayerPage)) { return(typeof(Views.LivePlayerPage)); } else { return(typeof(Views.BlankPage)); } }, sessionStateService); var name = nameof(PlayerViewManager.PrimaryViewPlayerNavigationService); Container.RegisterInstance(name, ns as INavigationService); }); var hohoemaInAppNotification = new Views.HohoemaInAppNotification() { VerticalAlignment = VerticalAlignment.Bottom }; var grid = new Grid() { Children = { playerWithPageContainer, hohoemaInAppNotification, } }; #if DEBUG menuPageBase.FocusEngaged += (__, args) => Debug.WriteLine("focus engagad: " + args.OriginalSource.ToString()); #endif return(grid); }
private async Task <HohoemaViewManager> GetEnsureSecondaryView() { if (CoreAppView == null) { var playerView = CoreApplication.CreateNewView(); HohoemaSecondaryViewFrameViewModel vm = null; int id = 0; ApplicationView view = null; INavigationService ns = null; await playerView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { playerView.TitleBar.ExtendViewIntoTitleBar = true; var content = new Views.HohoemaSecondaryViewFrame(); var frameFacade = new FrameFacadeAdapter(content.Frame); var sessionStateService = new SessionStateService(); ns = new FrameNavigationService(frameFacade , (pageToken) => { if (pageToken == nameof(Views.VideoPlayerPage)) { return(typeof(Views.VideoPlayerPage)); } else if (pageToken == nameof(Views.LivePlayerPage)) { return(typeof(Views.LivePlayerPage)); } else { return(typeof(Views.BlankPage)); } }, sessionStateService); vm = content.DataContext as HohoemaSecondaryViewFrameViewModel; Window.Current.Content = content; id = ApplicationView.GetApplicationViewIdForWindow(playerView.CoreWindow); view = ApplicationView.GetForCurrentView(); view.TitleBar.ButtonBackgroundColor = Windows.UI.Colors.Transparent; view.TitleBar.ButtonInactiveBackgroundColor = Windows.UI.Colors.Transparent; Window.Current.Activate(); await ApplicationViewSwitcher.TryShowAsStandaloneAsync(id, ViewSizePreference.Default, MainView.Id, ViewSizePreference.Default); // ウィンドウサイズの保存と復元 if (Helpers.DeviceTypeHelper.IsDesktop) { var localObjectStorageHelper = App.Current.Container.Resolve <Microsoft.Toolkit.Uwp.Helpers.LocalObjectStorageHelper>(); if (localObjectStorageHelper.KeyExists(secondary_view_size)) { view.TryResizeView(localObjectStorageHelper.Read <Size>(secondary_view_size)); } view.VisibleBoundsChanged += View_VisibleBoundsChanged; } view.Consolidated += SecondaryAppView_Consolidated; }); ViewId = id; AppView = view; _SecondaryViewVM = vm; CoreAppView = playerView; NavigationService = ns; } NowShowingSecondaryView = true; return(this); }
/// <summary> /// Initializes the Frame and its content. /// </summary> /// <param name="args">The <see cref="IActivatedEventArgs"/> instance containing the event data.</param> /// <returns>A task of a Frame that holds the app content.</returns> protected virtual async Task<Frame> InitializeFrameAsync(IActivatedEventArgs args) { CreateAndConfigureContainer(); EventAggregator = CreateEventAggregator(); // Create a Frame to act as the navigation context and navigate to the first page var rootFrame = CreateRootFrame(); if (ExtendedSplashScreenFactory != null) { Page extendedSplashScreen = this.ExtendedSplashScreenFactory.Invoke(args.SplashScreen); rootFrame.Content = extendedSplashScreen; } var frameFacade = new FrameFacadeAdapter(rootFrame, EventAggregator); //Initialize PrismApplication common services SessionStateService = CreateSessionStateService(); //Configure VisualStateAwarePage with the ability to get the session state for its frame SessionStateAwarePage.GetSessionStateForFrame = frame => SessionStateService.GetSessionStateForFrame(frameFacade); //Associate the frame with a key SessionStateService.RegisterFrame(frameFacade, "AppFrame"); NavigationService = CreateNavigationService(frameFacade, SessionStateService); DeviceGestureService = CreateDeviceGestureService(); DeviceGestureService.GoBackRequested += OnGoBackRequested; DeviceGestureService.GoForwardRequested += OnGoForwardRequested; // Set a factory for the ViewModelLocator to use the default resolution mechanism to construct view models Logger.Log("Configuring ViewModelLocator", Category.Debug, Priority.Low); ConfigureViewModelLocator(); OnRegisterKnownTypesForSerialization(); if (args.PreviousExecutionState == ApplicationExecutionState.Terminated) { await SessionStateService.RestoreSessionStateAsync(); } await OnInitializeAsync(args); if (args.PreviousExecutionState == ApplicationExecutionState.Terminated) { // Restore the saved session state and navigate to the last page visited try { SessionStateService.RestoreFrameState(); NavigationService.RestoreSavedNavigation(); _isRestoringFromTermination = true; } catch (SessionStateServiceException) { // Something went wrong restoring state. // Assume there is no state and continue } } return rootFrame; }
/// <summary> /// Initializes the Frame and its content. /// </summary> /// <param name="args">The <see cref="IActivatedEventArgs"/> instance containing the event data.</param> /// <returns>A task of a Frame that holds the app content.</returns> protected async Task <Frame> InitializeFrameAsync(IActivatedEventArgs args) { var rootFrame = Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); if (ExtendedSplashScreenFactory != null) { Page extendedSplashScreen = this.ExtendedSplashScreenFactory.Invoke(args.SplashScreen); rootFrame.Content = extendedSplashScreen; } var frameFacade = new FrameFacadeAdapter(rootFrame); //Initialize PrismApplication common services SessionStateService = new SessionStateService(); //Configure VisualStateAwarePage with the ability to get the session state for its frame VisualStateAwarePage.GetSessionStateForFrame = frame => SessionStateService.GetSessionStateForFrame(frameFacade); //Associate the frame with a key SessionStateService.RegisterFrame(frameFacade, "AppFrame"); NavigationService = CreateNavigationService(frameFacade, SessionStateService); //TODO: BDN Figure out what to do about settings pane stuff //SettingsPane.GetForCurrentView().CommandsRequested += OnCommandsRequested; // Set a factory for the ViewModelLocator to use the default resolution mechanism to construct view models ViewModelLocationProvider.SetDefaultViewModelFactory(Resolve); OnRegisterKnownTypesForSerialization(); if (args.PreviousExecutionState == ApplicationExecutionState.Terminated) { await SessionStateService.RestoreSessionStateAsync(); } OnInitialize(args); if (args.PreviousExecutionState == ApplicationExecutionState.Terminated) { // Restore the saved session state and navigate to the last page visited try { SessionStateService.RestoreFrameState(); NavigationService.RestoreSavedNavigation(); _isRestoringFromTermination = true; } catch (SessionStateServiceException) { // Something went wrong restoring state. // Assume there is no state and continue } } // Place the frame in the current Window Window.Current.Content = rootFrame; } return(rootFrame); }
public async Task PageTokenThatCannotBeResolved_ThrowsMeaningfulException() { await ExecuteOnUIThread(() => { var frame = new FrameFacadeAdapter(new Frame()); var sessionStateService = new MockSessionStateService(); var frameSessionState = new Dictionary<string, object>(); sessionStateService.GetSessionStateForFrameDelegate = (currentFrame) => frameSessionState; Func<string, Type> unresolvablePageTokenReturnsNull = pageToken => null; var navigationService = new FrameNavigationService(frame, unresolvablePageTokenReturnsNull, sessionStateService); Assert.ThrowsException<ArgumentException>( () => navigationService.Navigate("anything", 1) ); }); }
public async Task RestoreSavedNavigation_ClearsOldForwardNavigation() { await ExecuteOnUIThread(() => { var frame = new FrameFacadeAdapter(new Frame()); var sessionStateService = new MockSessionStateService(); var frameSessionState = new Dictionary<string, object>(); sessionStateService.GetSessionStateForFrameDelegate = (currentFrame) => frameSessionState; var navigationService = new FrameNavigationService(frame, (pageToken) => typeof(MockPageWithViewModel), sessionStateService); navigationService.Navigate("Page1", 1); Assert.AreEqual(1, frameSessionState.Count, "VM 1 state only"); navigationService.Navigate("Page2", 2); Assert.AreEqual(2, frameSessionState.Count, "VM 1 and 2"); navigationService.Navigate("Page3", 3); Assert.AreEqual(3, frameSessionState.Count, "VM 1, 2, and 3"); navigationService.GoBack(); Assert.AreEqual(2, ((Dictionary<string, object>)frameSessionState["ViewModel-2"]).Count); Assert.AreEqual(3, frameSessionState.Count, "VM 1, 2, and 3"); navigationService.Navigate("Page4", 4); Assert.AreEqual(0, ((Dictionary<string,object>)frameSessionState["ViewModel-2"]).Count); Assert.AreEqual(3, frameSessionState.Count, "VM 1, 2, and 4"); }); }
public async Task ViewModelOnNavigatedFromCalled_WithItsOwnStateDictionary() { await ExecuteOnUIThread(() => { var frame = new FrameFacadeAdapter(new Frame()); var sessionStateService = new MockSessionStateService(); var frameSessionState = new Dictionary<string, object>(); sessionStateService.GetSessionStateForFrameDelegate = (currentFrame) => frameSessionState; var navigationService = new FrameNavigationService(frame, (pageToken) => typeof(MockPageWithViewModel), sessionStateService); navigationService.Navigate("Page1", 1); Assert.AreEqual(1, frameSessionState.Count, "VM 1 state only"); navigationService.Navigate("Page2", 2); Assert.AreEqual(2, frameSessionState.Count, "VM 1 and 2"); navigationService.Navigate("Page1", 1); Assert.AreEqual(3, frameSessionState.Count, "VM 1, 2, and 1 again."); navigationService.Navigate("Page3", 3); Assert.AreEqual(4, frameSessionState.Count, "VM 1, 2, 1, and 3"); }); }
public async Task NavigateFromCurrentViewModel_Calls_VieModel_OnNavigatedFrom() { await ExecuteOnUIThread(() => { var frame = new FrameFacadeAdapter(new Frame()); bool viewModelNavigatedFromCalled = false; var viewModel = new MockPageViewModel(); viewModel.OnNavigatedFromCommand = (frameState, suspending) => { Assert.IsFalse(suspending); Assert.AreEqual(1, frameState["someValue"]); viewModelNavigatedFromCalled = true; }; var frameSessionState = new MockFrameSessionState(); frameSessionState.GetSessionStateForFrameDelegate = (currentFrame) => { var toReturn = new Dictionary<string, object>(); toReturn.Add("someValue", 1); return toReturn; }; var navigationService = new FrameNavigationService(frame, frameSessionState, (pageToken) => typeof(MockPage), null); // Set up the frame's content with a Page var view = new MockPage(); view.DataContext = viewModel; frame.Content = view; // Navigate to fire the NavigatedToCurrentViewModel navigationService.Navigate("Mock", 1); Assert.IsTrue(viewModelNavigatedFromCalled); }); }
private async Task <PlayerViewManager> GetEnsureSecondaryView() { if (IsMainView && SecondaryCoreAppView == null) { var playerView = CoreApplication.CreateNewView(); HohoemaSecondaryViewFrameViewModel vm = null; int id = 0; ApplicationView view = null; INavigationService ns = null; await playerView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { // SecondaryViewのスケジューラをセットアップ SecondaryViewScheduler = new CoreDispatcherScheduler(playerView.Dispatcher); playerView.TitleBar.ExtendViewIntoTitleBar = true; var content = new Views.HohoemaSecondaryViewFrame(); var frameFacade = new FrameFacadeAdapter(content.Frame, EventAggregator); var sessionStateService = new SessionStateService(); //sessionStateService.RegisterFrame(frameFacade, "secondary_view_player"); ns = new FrameNavigationService(frameFacade , (pageToken) => { if (pageToken == nameof(Views.VideoPlayerPage)) { return(typeof(Views.VideoPlayerPage)); } else if (pageToken == nameof(Views.LivePlayerPage)) { return(typeof(Views.LivePlayerPage)); } else { return(typeof(Views.BlankPage)); } }, sessionStateService); vm = content.DataContext as HohoemaSecondaryViewFrameViewModel; Window.Current.Content = content; id = ApplicationView.GetApplicationViewIdForWindow(playerView.CoreWindow); view = ApplicationView.GetForCurrentView(); view.TitleBar.ButtonBackgroundColor = Windows.UI.Colors.Transparent; view.TitleBar.ButtonInactiveBackgroundColor = Windows.UI.Colors.Transparent; Window.Current.Activate(); await ApplicationViewSwitcher.TryShowAsStandaloneAsync(id, ViewSizePreference.UseHalf, MainViewId, ViewSizePreference.UseHalf); // ウィンドウサイズの保存と復元 if (Services.Helpers.DeviceTypeHelper.IsDesktop) { var localObjectStorageHelper = App.Current.Container.Resolve <Microsoft.Toolkit.Uwp.Helpers.LocalObjectStorageHelper>(); if (localObjectStorageHelper.KeyExists(secondary_view_size)) { view.TryResizeView(localObjectStorageHelper.Read <Size>(secondary_view_size)); } view.VisibleBoundsChanged += View_VisibleBoundsChanged; } view.Consolidated += SecondaryAppView_Consolidated; }); SecondaryAppView = view; _SecondaryViewVM = vm; SecondaryCoreAppView = playerView; SecondaryViewPlayerNavigationService = ns; App.Current.Container.RegisterInstance(SECONDARY_VIEW_PLAYER_NAVIGATION_SERVICE, SecondaryViewPlayerNavigationService); } return(this); }
/// <summary> /// Initializes the Frame and its content. /// </summary> /// <param name="args">The <see cref="IActivatedEventArgs"/> instance containing the event data.</param> /// <returns>A task of a Frame that holds the app content.</returns> protected async Task<Frame> InitializeFrameAsync(IActivatedEventArgs args) { var rootFrame = Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = (RootFrameFactory != null ? RootFrameFactory() : new Frame()); if (ExtendedSplashScreenFactory != null) { Page extendedSplashScreen = this.ExtendedSplashScreenFactory.Invoke(args.SplashScreen); rootFrame.Content = extendedSplashScreen; } var frameFacade = new FrameFacadeAdapter(rootFrame); //Initialize MvvmAppBase common services SessionStateService = new SessionStateService(); //Configure VisualStateAwarePage with the ability to get the session state for its frame VisualStateAwarePage.GetSessionStateForFrame = frame => SessionStateService.GetSessionStateForFrame(frameFacade); //Associate the frame with a key SessionStateService.RegisterFrame(frameFacade, "AppFrame"); NavigationService = CreateNavigationService(frameFacade, SessionStateService); #if WINDOWS_APP SettingsPane.GetForCurrentView().CommandsRequested += OnCommandsRequested; #endif #if WINDOWS_PHONE_APP HardwareButtons.BackPressed += OnHardwareButtonsBackPressed; #endif // Set a factory for the ViewModelLocator to use the default resolution mechanism to construct view models ViewModelLocationProvider.SetDefaultViewModelFactory(Resolve); OnRegisterKnownTypesForSerialization(); if (args.PreviousExecutionState == ApplicationExecutionState.Terminated) { await SessionStateService.RestoreSessionStateAsync(); } await OnInitializeAsync(args); if (args.PreviousExecutionState == ApplicationExecutionState.Terminated) { // Restore the saved session state and navigate to the last page visited try { SessionStateService.RestoreFrameState(); NavigationService.RestoreSavedNavigation(); _isRestoringFromTermination = true; } catch (SessionStateServiceException) { // Something went wrong restoring state. // Assume there is no state and continue } } // Place the frame in the current Window Window.Current.Content = rootFrame; } return rootFrame; }
public async Task Suspending_Calls_VieModel_OnNavigatedFrom() { await ExecuteOnUIThread(() => { var frame = new FrameFacadeAdapter(new Frame()); var frameSessionState = new MockFrameSessionState(); frameSessionState.GetSessionStateForFrameDelegate = (currentFrame) => { var toReturn = new Dictionary<string, object>(); toReturn.Add("someValue", 1); return toReturn; }; var restorableStateService = new MockSuspensionManagerState(); var navigationService = new FrameNavigationService(frame, frameSessionState, (pageToken) => typeof(MockPage), restorableStateService); navigationService.Navigate("Mock", 1); var viewModel = new MockPageViewModel(); viewModel.OnNavigatedFromCommand = (frameState, suspending) => { Assert.IsTrue(suspending); Assert.AreEqual(1, frameState["someValue"]); }; var page = (MockPage)frame.Content; page.DataContext = viewModel; navigationService.Suspending(); }); }
public async Task NavigateFromCurrentViewModel_Calls_VieModel_OnNavigatedFrom() { await ExecuteOnUIThread(() => { var frame = new FrameFacadeAdapter(new Frame()); bool viewModelNavigatedFromCalled = false; var viewModel = new MockPageViewModel(); viewModel.OnNavigatedFromCommand = (frameState, suspending) => { Assert.IsFalse(suspending); viewModelNavigatedFromCalled = true; }; var sessionStateService = new MockSessionStateService(); sessionStateService.GetSessionStateForFrameDelegate = (currentFrame) => new Dictionary<string, object>(); var navigationService = new FrameNavigationService(frame, (pageToken) => typeof(MockPage), sessionStateService); // Initial navigatio navigationService.Navigate("page0", 0); // Set up the frame's content with a Page var view = new MockPage(); view.DataContext = viewModel; frame.Content = view; // Navigate to fire the NavigatedToCurrentViewModel navigationService.Navigate("page1", 1); Assert.IsTrue(viewModelNavigatedFromCalled); }); }
public async Task Suspending_Calls_VieModel_OnNavigatedFrom() { await ExecuteOnUIThread(() => { var frame = new FrameFacadeAdapter(new Frame()); var sessionStateService = new MockSessionStateService(); sessionStateService.GetSessionStateForFrameDelegate = (currentFrame) => new Dictionary<string, object>(); var navigationService = new FrameNavigationService(frame, (pageToken) => typeof(MockPage), sessionStateService); navigationService.Navigate("Mock", 1); var viewModel = new MockPageViewModel(); viewModel.OnNavigatedFromCommand = (frameState, suspending) => { Assert.IsTrue(suspending); }; var page = (MockPage)frame.Content; page.DataContext = viewModel; navigationService.Suspending(); }); }
/// <summary> /// Initializes the Frame and its content. /// </summary> /// <param name="args">The <see cref="IActivatedEventArgs"/> instance containing the event data.</param> /// <returns>A task of a Frame that holds the app content.</returns> protected async Task <Frame> InitializeFrameAsync(IActivatedEventArgs args) { var rootFrame = Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); if (ExtendedSplashScreenFactory != null) { Page extendedSplashScreen = this.ExtendedSplashScreenFactory.Invoke(args.SplashScreen); rootFrame.Content = extendedSplashScreen; } var frameFacade = new FrameFacadeAdapter(rootFrame); //Initialize PrismApplication common services SessionStateService = new SessionStateService(); //Configure VisualStateAwarePage with the ability to get the session state for its frame VisualStateAwarePage.GetSessionStateForFrame = frame => SessionStateService.GetSessionStateForFrame(frameFacade); //Associate the frame with a key SessionStateService.RegisterFrame(frameFacade, "AppFrame"); NavigationService = CreateNavigationService(frameFacade, SessionStateService); if (ApiInformation.IsTypePresent("Windows.UI.ApplicationSettings.SettingsPane")) { // TODO BL : keep an eye on MSDN for future SDK release updates on SettingsPane #pragma warning disable CS0618 // Type or member is obsolete // Still marked on MSDN as a valid type for the Windows family SettingsPane.GetForCurrentView().CommandsRequested += OnCommandsRequested; #pragma warning restore CS0618 } // Register hardware back button event if present if (ApiInformation.IsEventPresent("Windows.Phone.UI.Input.HardwareButtons", "BackPressed")) { HardwareButtons.BackPressed += HardwareButtonsOnBackPressed; } // Set a factory for the ViewModelLocator to use the default resolution mechanism to construct view models ViewModelLocationProvider.SetDefaultViewModelFactory(Resolve); OnRegisterKnownTypesForSerialization(); if (args.PreviousExecutionState == ApplicationExecutionState.Terminated) { await SessionStateService.RestoreSessionStateAsync(); } await OnInitializeAsync(args); if (args.PreviousExecutionState == ApplicationExecutionState.Terminated) { // Restore the saved session state and navigate to the last page visited try { SessionStateService.RestoreFrameState(); NavigationService.RestoreSavedNavigation(); _isRestoringFromTermination = true; } catch (SessionStateServiceException) { // Something went wrong restoring state. // Assume there is no state and continue } } // Place the frame in the current Window Window.Current.Content = rootFrame; } return(rootFrame); }
public async Task Resuming_Calls_ViewModel_OnNavigatedTo() { await ExecuteOnUIThread(() => { var frame = new FrameFacadeAdapter(new Frame()); var sessionStateService = new MockSessionStateService(); sessionStateService.GetSessionStateForFrameDelegate = (currentFrame) => new Dictionary<string, object>(); var navigationService = new FrameNavigationService(frame, (pageToken) => typeof(MockPage), sessionStateService); navigationService.Navigate("Mock", 1); var viewModel = new MockPageViewModel(); viewModel.OnNavigatedToCommand = (navigationParameter, navigationMode, frameState) => { Assert.AreEqual(NavigationMode.Refresh, navigationMode); }; var page = (MockPage)frame.Content; page.DataContext = viewModel; navigationService.RestoreSavedNavigation(); }); }
public async Task GoBack_When_CanGoBack() { await ExecuteOnUIThread(() => { var frame = new FrameFacadeAdapter(new Frame()); var sessionStateService = new MockSessionStateService(); sessionStateService.GetSessionStateForFrameDelegate = (currentFrame) => new Dictionary<string, object>(); var navigationService = new FrameNavigationService(frame, (pageToken) => typeof(MockPage), sessionStateService); bool resultFirstNavigation = navigationService.Navigate("MockPage", 1); Assert.IsInstanceOfType(frame.Content, typeof(MockPage)); Assert.AreEqual(1, ((MockPage)frame.Content).PageParameter); Assert.IsFalse(navigationService.CanGoBack()); bool resultSecondNavigation = navigationService.Navigate("Mock", 2); Assert.IsInstanceOfType(frame.Content, typeof(MockPage)); Assert.AreEqual(2, ((MockPage)frame.Content).PageParameter); Assert.IsTrue(navigationService.CanGoBack()); navigationService.GoBack(); Assert.IsInstanceOfType(frame.Content, typeof(MockPage)); Assert.AreEqual(1, ((MockPage)frame.Content).PageParameter); Assert.IsFalse(navigationService.CanGoBack()); }); }
/// <summary> /// Initializes the Frame and its content. /// </summary> /// <param name="args">The <see cref="IActivatedEventArgs"/> instance containing the event data.</param> /// <returns>A task of a Frame that holds the app content.</returns> protected virtual async Task <Frame> InitializeFrameAsync(IActivatedEventArgs args) { CreateAndConfigureContainer(); EventAggregator = CreateEventAggregator(); // Create a Frame to act as the navigation context and navigate to the first page var rootFrame = CreateRootFrame(); if (ExtendedSplashScreenFactory != null) { Page extendedSplashScreen = ExtendedSplashScreenFactory.Invoke(args.SplashScreen); rootFrame.Content = extendedSplashScreen; } var frameFacade = new FrameFacadeAdapter(rootFrame, EventAggregator); //Initialize PrismApplication common services SessionStateService = CreateSessionStateService(); //Configure VisualStateAwarePage with the ability to get the session state for its frame SessionStateAwarePage.GetSessionStateForFrame = frame => SessionStateService.GetSessionStateForFrame(frameFacade); //Associate the frame with a key SessionStateService.RegisterFrame(frameFacade, "AppFrame"); NavigationService = CreateNavigationService(frameFacade, SessionStateService); DeviceGestureService = CreateDeviceGestureService(); DeviceGestureService.GoBackRequested += OnGoBackRequested; DeviceGestureService.GoForwardRequested += OnGoForwardRequested; // Set a factory for the ViewModelLocator to use the default resolution mechanism to construct view models Logger.Log("Configuring ViewModelLocator", Category.Debug, Priority.Low); ConfigureViewModelLocator(); OnRegisterKnownTypesForSerialization(); bool canRestore = await SessionStateService.CanRestoreSessionStateAsync(); bool shouldRestore = canRestore && ShouldRestoreState(args); if (shouldRestore) { await SessionStateService.RestoreSessionStateAsync(); } await OnInitializeAsync(args); if (shouldRestore) { // Restore the saved session state and navigate to the last page visited try { SessionStateService.RestoreFrameState(); NavigationService.RestoreSavedNavigation(); _isRestoringFromTermination = true; } catch (SessionStateServiceException) { // Something went wrong restoring state. // Assume there is no state and continue } } return(rootFrame); }
/// <summary> /// Initializes the Frame and its content. /// </summary> /// <param name="args">The <see cref="IActivatedEventArgs"/> instance containing the event data.</param> /// <returns>A task of a Frame that holds the app content.</returns> protected Frame InitializeFrame(IActivatedEventArgs args) { // Create a Frame to act as the navigation context and navigate to the first page var rootFrame = new Frame() { CacheSize = RootFrameCacheSize }; if (ExtendedSplashScreenFactory != null) { Page extendedSplashScreen = this.ExtendedSplashScreenFactory.Invoke(args.SplashScreen); rootFrame.Content = extendedSplashScreen; } rootFrame.Navigated += OnNavigated; var frameFacade = new FrameFacadeAdapter(rootFrame); //Initialize PrismApplication common services SessionStateService = CreateSessionStateService(); //Configure VisualStateAwarePage with the ability to get the session state for its frame VisualStateAwarePage.GetSessionStateForFrame = frame => SessionStateService.GetSessionStateForFrame(frameFacade); //Associate the frame with a key SessionStateService.RegisterFrame(frameFacade, "AppFrame"); NavigationService = CreateNavigationService(frameFacade, SessionStateService); DeviceGestureService = CreateDeviceGestureService(); DeviceGestureService.GoBackRequested += OnGoBackRequested; DeviceGestureService.GoForwardRequested += OnGoForwardRequested; #if WINDOWS_APP global::Windows.UI.ApplicationSettings.SettingsPane.GetForCurrentView().CommandsRequested += OnCommandsRequested; #endif // Set a factory for the ViewModelLocator to use the default resolution mechanism to construct view models ViewModelLocationProvider.SetDefaultViewModelFactory(Resolve); OnRegisterKnownTypesForSerialization(); if (args.PreviousExecutionState == ApplicationExecutionState.Terminated) { SessionStateService.RestoreSessionStateAsync().Wait(); } OnInitialize(args); if (args.PreviousExecutionState == ApplicationExecutionState.Terminated) { // Restore the saved session state and navigate to the last page visited try { SessionStateService.RestoreFrameState(); NavigationService.RestoreSavedNavigation(); _isRestoringFromTermination = true; } catch (SessionStateServiceException) { Logger.Log("Unable to restore session state.", Category.Exception, Priority.None); // Something went wrong restoring state. // Assume there is no state and continue } } return rootFrame; }