/// <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> public INavigationService NavigationServiceSetup( BackButton backButton, ExistingContent existingContent, Frame frame) { frame.Language = ApplicationLanguages.Languages[0]; frame.Content = existingContent == ExistingContent.Include ? Window.Current.Content : null; var navigationService = new NavigationService(frame); 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 frame.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 frame.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(); } } } return(navigationService); }
private void RaiseForwardRequested() { var args = new HandledEventArgs(); ForwardRequested?.Invoke(null, args); if (args.Handled) { return; } foreach (var frame in WindowWrapper.Current().NavigationServices.Select(x => x.FrameFacade)) { frame.RaiseForwardRequested(args); if (args.Handled) { return; } } NavigationService.GoForward(); }
/// <summary> /// Default Hardware/Shell Back handler overrides standard Back behavior /// that navigates to previous app in the app stack to instead cause a backward page navigation. /// Views or Viewodels can override this behavior by handling the BackRequested /// event and setting the Handled property of the BackRequestedEventArgs to true. /// </summary> private void RaiseBackRequested(ref bool handled) { var args = new HandledEventArgs(); BackRequested?.Invoke(null, args); if (handled = args.Handled) { return; } foreach (var frame in WindowWrapper.Current().NavigationServices.Select(x => x.FrameFacade).Reverse()) { frame.RaiseBackRequested(args); if (handled = args.Handled) { return; } } NavigationService.GoBack(); }