private Frame InitializeFrame(ILaunchActivatedEventArgs e) { // do not recreate the frame if (Window.Current.Content is Frame) { return(Window.Current.Content as Frame); } // first show the splash var splashScreen = default(UIElement); if (SplashFactory != null) { splashScreen = SplashFactory(e.SplashScreen); Window.Current.Content = splashScreen; Window.Current.Activate(); } // next create frame var frame = new Frame { Language = Windows.Globalization.ApplicationLanguages.Languages[0] }; frame.Navigated += (s, args) => { SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = (ShowShellBackButton && frame.CanGoBack) ? AppViewBackButtonVisibility.Visible : AppViewBackButtonVisibility.Collapsed; }; Window.Current.Content = frame; // next setup the default view var navigationService = new Services.NavigationService.NavigationService(frame); WindowWrapper.Current().NavigationServices.Add(navigationService); // expire any state (based on expiry) DateTime cacheDate; var otherwise = DateTime.MinValue.ToString(); 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(); } } } else /* no date, that's okay */ } {
/// <summary> /// Craetes a new FamFrame and adds the resulting NavigationService 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 Services.NavigationService.NavigationService NavigationServiceFactory(BackButton backButton, ExistingContent existingContent) { var frame = new Frame { Language = Windows.Globalization.ApplicationLanguages.Languages[0], Content = (existingContent == ExistingContent.Include) ? Window.Current.Content : null, }; var navigationService = new Services.NavigationService.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(); 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(); } } } else { // no date, that's okay } return(navigationService); }
private async void InternalLaunchAsync(ILaunchActivatedEventArgs e) { UIElement splashScreen = default(UIElement); if (SplashFactory != null) { splashScreen = SplashFactory(e.SplashScreen); Window.Current.Content = splashScreen; } RootFrame = RootFrame ?? new Frame(); RootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0]; NavigationService = new Services.NavigationService.NavigationService(RootFrame); // the user may override to set custom content await OnInitializeAsync(); if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { try { /* TODO: restore state */ } finally { await OnLaunchedAsync(e); } } else { await OnLaunchedAsync(e); } // if the user didn't already set custom content use rootframe if (Window.Current.Content == splashScreen) { Window.Current.Content = RootFrame; } if (Window.Current.Content == null) { Window.Current.Content = RootFrame; } Window.Current.Activate(); // Hook up the default Back handler Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested; }
private async void InternalLaunchAsync(ILaunchActivatedEventArgs e) { UIElement splashScreen = default(UIElement); if (SplashFactory != null) { splashScreen = SplashFactory(e.SplashScreen); Window.Current.Content = splashScreen; } // setup frame RootFrame = RootFrame ?? new Frame(); RootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0]; NavigationService = new Services.NavigationService.NavigationService(RootFrame); // expire state var state = NavigationService.State(); if (state.Values.ContainsKey(CacheKey)) { DateTime cacheDate; if (DateTime.TryParse(state.Values[CacheKey]?.ToString(), out cacheDate)) { var cacheAge = DateTime.Now.Subtract(cacheDate); if (cacheAge >= CacheMaxDuration) { foreach (var item in state.Containers) { state.DeleteContainer(item.Key); } state.Values.Clear(); } } } // the user may override to set custom content await OnInitializeAsync(); switch (e.PreviousExecutionState) { case ApplicationExecutionState.NotRunning: case ApplicationExecutionState.Running: case ApplicationExecutionState.Suspended: { // launch if not restored await OnStartAsync(StartKind.Launch, e); break; } case ApplicationExecutionState.Terminated: await OnStartAsync(StartKind.Launch, e); break; case ApplicationExecutionState.ClosedByUser: { // restore if you need to/can do var restored = NavigationService.RestoreSavedNavigation(); if (!restored) { await OnStartAsync(StartKind.Launch, e); } break; } } // if the user didn't already set custom content use rootframe if (Window.Current.Content == splashScreen) { Window.Current.Content = RootFrame; } if (Window.Current.Content == null) { Window.Current.Content = RootFrame; } // ensure active Window.Current.Activate(); // Hook up the default Back handler Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested += (s, args) => { args.Handled = true; OnBackRequested(); }; // Hook up keyboard and mouse Back handler var keyboard = new Services.KeyboardService.KeyboardService(); keyboard.AfterBackGesture = () => OnBackRequested(); // Hook up keyboard and house Forward handler keyboard.AfterForwardGesture = () => OnForwardRequested(); }
private async void InternalLaunchAsync(ILaunchActivatedEventArgs e) { // first handle prelaunch, which will not continue if ((e.Kind == ActivationKind.Launch) && ((e as LaunchActivatedEventArgs)?.PrelaunchActivated ?? false)) { OnPrelaunch(); return; } // now handle normal activation UIElement splashScreen = default(UIElement); if (SplashFactory != null) { splashScreen = SplashFactory(e.SplashScreen); Window.Current.Content = splashScreen; } // setup frame var frame = new Frame { Language = global::Windows.Globalization.ApplicationLanguages.Languages[0] }; frame.Navigated += (s, args) => { global::Windows.UI.Core.SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = (ShowShellBackButton && frame.CanGoBack) ? AppViewBackButtonVisibility.Visible : AppViewBackButtonVisibility.Collapsed; }; // setup default view var view = WindowWrapper.ActiveWrappers.First(); var navigationService = new Services.NavigationService.NavigationService(frame); view.NavigationServices.Add(navigationService); // expire state (based on expiry) DateTime cacheDate; var otherwise = DateTime.MinValue.ToString(); if (DateTime.TryParse(navigationService.Frame.GetFrameState(CacheKey, 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.Frame.ClearFrameState(); } } } else { // no date, that's okay } // the user may override to set custom content await OnInitializeAsync(); switch (e.PreviousExecutionState) { case ApplicationExecutionState.NotRunning: case ApplicationExecutionState.Running: case ApplicationExecutionState.Suspended: { // launch if not restored await OnStartAsync(StartKind.Launch, e); break; } case ApplicationExecutionState.ClosedByUser: case ApplicationExecutionState.Terminated: { // restore if you need to/can do var restored = navigationService.RestoreSavedNavigation(); if (!restored) { await OnStartAsync(StartKind.Launch, e); } break; } } // if the user didn't already set custom content use rootframe if (Window.Current.Content == splashScreen) { Window.Current.Content = frame; } if (Window.Current.Content == null) { Window.Current.Content = frame; } // ensure active Window.Current.Activate(); // Hook up the default Back handler global::Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested += (s, args) => { // TODO: handled=true canisn't true at end of backstack args.Handled = true; RaiseBackRequested(); }; // Hook up keyboard and mouse Back handler var keyboard = new Services.KeyboardService.KeyboardService(); keyboard.AfterBackGesture = () => RaiseBackRequested(); // Hook up keyboard and house Forward handler keyboard.AfterForwardGesture = () => RaiseForwardRequested(); }
/// <summary> /// Craetes a new FamFrame and adds the resulting NavigationService 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 Services.NavigationService.NavigationService NavigationServiceFactory(BackButton backButton, ExistingContent existingContent) { var frame = new Frame { Language = Windows.Globalization.ApplicationLanguages.Languages[0], Content = (existingContent == ExistingContent.Include) ? Window.Current.Content : null, }; var navigationService = new Services.NavigationService.NavigationService(frame); 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(); 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(); } } } else { // no date, that's okay } return navigationService; }
private async void InternalLaunchAsync(ILaunchActivatedEventArgs e) { UIElement splashScreen = default(UIElement); if (SplashFactory != null) { splashScreen = SplashFactory(e.SplashScreen); Window.Current.Content = splashScreen; } RootFrame = RootFrame ?? new Frame(); RootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0]; NavigationService = new Services.NavigationService.NavigationService(RootFrame); // the user may override to set custom content await OnInitializeAsync(); switch (e.PreviousExecutionState) { case ApplicationExecutionState.NotRunning: case ApplicationExecutionState.Running: case ApplicationExecutionState.Suspended: { // launch if not restored await OnStartAsync(StartKind.Launch, e); break; } case ApplicationExecutionState.Terminated: case ApplicationExecutionState.ClosedByUser: { if (EnableRestoreNavigationState) { // restore if you need to/can do var restored = NavigationService.RestoreSavedNavigation(); if (!restored) await OnStartAsync(StartKind.Launch, e); } else { await OnStartAsync(StartKind.Launch, e); } break; } } // if the user didn't already set custom content use rootframe if (Window.Current.Content == splashScreen) { Window.Current.Content = RootFrame; } if (Window.Current.Content == null) { Window.Current.Content = RootFrame; } // ensure active Window.Current.Activate(); // Hook up the default Back handler Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested += (s, args) => { args.Handled = true; OnBackRequested(); }; // Hook up keyboard and mouse Back handler var keyboard = new Services.KeyboardService.KeyboardService(); keyboard.AfterBackGesture = () => OnBackRequested(); // Hook up keyboard and house Forward handler keyboard.AfterForwardGesture = () => OnForwardRequested(); }
// this is private because there's no reason for the developer to call this private Frame InitializeFrame(ILaunchActivatedEventArgs e) { // do not recreate the frame if (Window.Current.Content is Frame) return Window.Current.Content as Frame; // first show the splash var splashScreen = default(UIElement); if (SplashFactory != null) { splashScreen = SplashFactory(e.SplashScreen); Window.Current.Content = splashScreen; Window.Current.Activate(); } else { // if there is no SplashScreen then the default/static splash will show. } // in any case, next create a new, default frame var defaultFrame = new Frame { Language = Windows.Globalization.ApplicationLanguages.Languages[0] }; // set default frame as primary, default visual Window.Current.Content = defaultFrame; // next setup the default view var navigationService = new Services.NavigationService.NavigationService(defaultFrame); WindowWrapper.Current().NavigationServices.Add(navigationService); // this anon method will be used to refresh the shell back button Action updateShellBack = () => { // show the shell back only if there is anywhere to go in the default frame SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = (ShowShellBackButton && NavigationService.Frame.CanGoBack) ? AppViewBackButtonVisibility.Visible : AppViewBackButtonVisibility.Collapsed; }; // update shell back when backstack changes // only the default frame in this case because secondary should not dismiss the app defaultFrame.RegisterPropertyChangedCallback(Frame.BackStackDepthProperty, (s, args) => updateShellBack()); // update shell back when navigation occurs // only the default frame in this case because secondary should not dismiss the app defaultFrame.Navigated += (s, args) => updateShellBack(); // expire any state (based on expiry) DateTime cacheDate; // default the cache age to very fresh if not known var otherwise = DateTime.MinValue.ToString(); 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(); } } } else { // no date, that's okay } // finally return our new frame return defaultFrame; }
public ShellPage(Frame frame) { this.InitializeComponent(); this.MySplitView.Content = frame; _navigationService = (App.Current as Common.BootStrapper).NavigationService; }
private async void InternalLaunchAsync(ILaunchActivatedEventArgs e) { UIElement splashScreen = default(UIElement); if (SplashFactory != null) { splashScreen = SplashFactory(e.SplashScreen); Window.Current.Content = splashScreen; } RootFrame = RootFrame ?? new Frame(); RootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0]; NavigationService = new Services.NavigationService.NavigationService(RootFrame); // the user may override to set custom content await OnInitializeAsync(); switch (e.PreviousExecutionState) { case ApplicationExecutionState.NotRunning: case ApplicationExecutionState.Running: case ApplicationExecutionState.Suspended: { // launch if not restored await OnStartAsync(StartKind.Launch, e); break; } case ApplicationExecutionState.Terminated: case ApplicationExecutionState.ClosedByUser: { if (EnableRestoreNavigationState) { // restore if you need to/can do var restored = NavigationService.RestoreSavedNavigation(); if (!restored) { await OnStartAsync(StartKind.Launch, e); } } else { await OnStartAsync(StartKind.Launch, e); } break; } } // if the user didn't already set custom content use rootframe if (Window.Current.Content == splashScreen) { Window.Current.Content = RootFrame; } if (Window.Current.Content == null) { Window.Current.Content = RootFrame; } // ensure active Window.Current.Activate(); // Hook up the default Back handler Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested += (s, args) => { args.Handled = true; OnBackRequested(); }; // Hook up keyboard and mouse Back handler var keyboard = new Services.KeyboardService.KeyboardService(); keyboard.AfterBackGesture = () => OnBackRequested(); // Hook up keyboard and house Forward handler keyboard.AfterForwardGesture = () => OnForwardRequested(); }
// this is private because there's no reason for the developer to call this private Frame InitializeFrame(ILaunchActivatedEventArgs e) { // do not recreate the frame if (Window.Current.Content is Frame) { return(Window.Current.Content as Frame); } // first show the splash var splashScreen = default(UIElement); if (SplashFactory != null) { splashScreen = SplashFactory(e.SplashScreen); Window.Current.Content = splashScreen; Window.Current.Activate(); } else { // if there is no SplashScreen then the default/static splash will show. } // in any case, next create a new, default frame var defaultFrame = new Frame { Language = Windows.Globalization.ApplicationLanguages.Languages[0] }; // set default frame as primary, default visual Window.Current.Content = defaultFrame; // next setup the default view var navigationService = new Services.NavigationService.NavigationService(defaultFrame); WindowWrapper.Current().NavigationServices.Add(navigationService); // this anon method will be used to refresh the shell back button Action updateShellBack = () => { // show the shell back only if there is anywhere to go in the default frame SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = (ShowShellBackButton && NavigationService.Frame.CanGoBack) ? AppViewBackButtonVisibility.Visible : AppViewBackButtonVisibility.Collapsed; }; // update shell back when backstack changes // only the default frame in this case because secondary should not dismiss the app defaultFrame.RegisterPropertyChangedCallback(Frame.BackStackDepthProperty, (s, args) => updateShellBack()); // update shell back when navigation occurs // only the default frame in this case because secondary should not dismiss the app defaultFrame.Navigated += (s, args) => updateShellBack(); // expire any state (based on expiry) DateTime cacheDate; // default the cache age to very fresh if not known var otherwise = DateTime.MinValue.ToString(); 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(); } } } else { // no date, that's okay } // finally return our new frame return(defaultFrame); }
private async void InternalLaunchAsync(ILaunchActivatedEventArgs e) { // first handle prelaunch, which will not continue if ((e.Kind == ActivationKind.Launch) && ((e as LaunchActivatedEventArgs)?.PrelaunchActivated ?? false)) { OnPrelaunch(); return; } // now handle normal activation UIElement splashScreen = default(UIElement); if (SplashFactory != null) { splashScreen = SplashFactory(e.SplashScreen); Window.Current.Content = splashScreen; } // setup frame var frame = new Frame { Language = global::Windows.Globalization.ApplicationLanguages.Languages[0] }; frame.Navigated += (s, args) => { global::Windows.UI.Core.SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = (ShowShellBackButton && frame.CanGoBack) ? AppViewBackButtonVisibility.Visible : AppViewBackButtonVisibility.Collapsed; }; // setup default view var view = WindowWrapper.ActiveWrappers.First(); var navigationService = new Services.NavigationService.NavigationService(frame); view.NavigationServices.Add(navigationService); // expire state (based on expiry) DateTime cacheDate; var otherwise = DateTime.MinValue.ToString(); if (DateTime.TryParse(navigationService.Frame.GetFrameState(CacheKey, 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.Frame.ClearFrameState(); } } } else { // no date, that's okay } // the user may override to set custom content await OnInitializeAsync(); switch (e.PreviousExecutionState) { case ApplicationExecutionState.NotRunning: case ApplicationExecutionState.Running: case ApplicationExecutionState.Suspended: { // launch if not restored await OnStartAsync(StartKind.Launch, e); break; } case ApplicationExecutionState.ClosedByUser: case ApplicationExecutionState.Terminated: { // restore if you need to/can do var restored = navigationService.RestoreSavedNavigation(); if (!restored) { await OnStartAsync(StartKind.Launch, e); } break; } } // if the user didn't already set custom content use rootframe if (Window.Current.Content == splashScreen) { Window.Current.Content = frame; } if (Window.Current.Content == null) { Window.Current.Content = frame; } // ensure active Window.Current.Activate(); // Hook up the default Back handler global::Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested += (s, args) => { args.Handled = true; RaiseBackRequested(); }; // Hook up keyboard and mouse Back handler var keyboard = new Services.KeyboardService.KeyboardService(); keyboard.AfterBackGesture = () => RaiseBackRequested(); // Hook up keyboard and house Forward handler keyboard.AfterForwardGesture = () => RaiseForwardRequested(); }