/// <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); }
protected virtual async Task <Frame> InitializeFrameAsync(IActivatedEventArgs args) { var services = CreateServices(); var rootFrame = CreateRootFrame(services); var eventAggregator = CreateEventAggregator(services); var frameFacade = CreateFrameFacade(services, rootFrame, eventAggregator); this.SessionStateService = CreateSessionStateService(services); this.NavigationService = CreateNavigationService(services, frameFacade, this.SessionStateService); services.AddSingleton <Frame>(rootFrame); services.AddSingleton <IEventAggregator>(eventAggregator); services.AddSingleton <IFrameFacade>(frameFacade); services.AddSingleton <ISessionStateService>(this.SessionStateService); services.AddSingleton <INavigationService>(this.NavigationService); ConfigureServices(services); if (ExtendedSplashScreenFactory != null) { Page extendedSplashScreen = ExtendedSplashScreenFactory.Invoke(args.SplashScreen); rootFrame.Content = extendedSplashScreen; } this.Provider = services.BuildServiceProvider(); var deviceGestureService = this.Provider.GetRequiredService <IDeviceGestureService>(); SessionStateAwarePage.GetSessionStateForFrame = frame => SessionStateService.GetSessionStateForFrame(frameFacade); //Associate the frame with a key SessionStateService.RegisterFrame(frameFacade, "AppFrame"); deviceGestureService.GoBackRequested += OnGoBackRequested; deviceGestureService.GoForwardRequested += OnGoForwardRequested; deviceGestureService.UseTitleBarBackButton = true; ConfigureViewModelLocator(); OnRegisterKnownTypesForSerialization(); bool canRestore = await SessionStateService.CanRestoreSessionStateAsync(); bool shouldRestore = canRestore && ShouldRestoreState(args); if (shouldRestore) { await SessionStateService.RestoreSessionStateAsync(); } Configure(this.Provider); 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); }