/// <summary> /// Creates a new NavigationService from the gived Frame to the /// WindowWrapper collection. In addition, it optionally will setup the /// shell back button to react to the nav of the Frame. /// A developer should call this when creating a new/secondary frame. /// The shell back button should only be setup one time. /// </summary> private void InternalNavigationServiceSetup( BackButton backButton, ExistingContent existingContent) { RootFrame.Language = ApplicationLanguages.Languages[0]; RootFrame.Content = existingContent == ExistingContent.Include ? Window.Current.Content : null; var navigationService = Kernel.Resolve <INavigationService>(); navigationService.FrameFacade.BackButtonHandling = backButton; WindowWrapper.Current().NavigationServices.Add(navigationService); if (backButton == BackButton.Attach) { // TODO: unattach others // update shell back when backstack changes // only the default frame in this case because secondary should not dismiss the app RootFrame.RegisterPropertyChangedCallback(Frame.BackStackDepthProperty, (s, args) => UpdateShellBackButton()); // update shell back when navigation occurs // only the default frame in this case because secondary should not dismiss the app RootFrame.Navigated += (s, args) => UpdateShellBackButton(); } // this is always okay to check, default or not // expire any state (based on expiry) DateTime cacheDate; // default the cache age to very fresh if not known var otherwise = DateTime.MinValue.ToString(CultureInfo.InvariantCulture); if (DateTime.TryParse(navigationService.FrameFacade.GetFrameState(CacheDateKey, otherwise), out cacheDate)) { var cacheAge = DateTime.Now.Subtract(cacheDate); if (cacheAge >= CacheMaxDuration) { // clear state in every nav service in every view foreach (var service in WindowWrapper.ActiveWrappers.SelectMany(x => x.NavigationServices)) { service.FrameFacade.ClearFrameState(); } } } }