/// <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> private 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(); 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); FlyoutService = new FlyoutService(); FlyoutService.FlyoutResolver = CreateFlyoutView; SettingsPane.GetForCurrentView().CommandsRequested += OnCommandsRequested; // Set a factory for the ViewModelLocator to use the default resolution mechanism to construct view models ViewModelLocator.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(); } 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); }
/// <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> private 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(); 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); FlyoutService = new FlyoutService(); FlyoutService.FlyoutResolver = CreateFlyoutView; SettingsPane.GetForCurrentView().CommandsRequested += OnCommandsRequested; // Set a factory for the ViewModelLocator to use the default resolution mechanism to construct view models ViewModelLocator.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(); } 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; }