private async Task ShowWindow(LaunchActivatedEventArgs e) { NavigationRootPage rootPage = Window.Current.Content as NavigationRootPage; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootPage == null) { rootPage = new NavigationRootPage(); // Retrieve the root Frame to act as the navigation context and navigate to the first page Frame rootFrame = (Frame)rootPage.FindName("rootFrame"); if (rootFrame == null) { throw new Exception("Root frame not found"); } // Associate the frame with a SuspensionManager key. SuspensionManager.RegisterFrame(rootFrame, "AppFrame"); // Set the default language rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0]; rootFrame.NavigationFailed += OnNavigationFailed; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { // Restore the saved session state only when appropriate try { await SuspensionManager.RestoreAsync(); } catch (SuspensionManagerException) { //Something went wrong restoring state. //Assume there is no state and continue } } if (rootFrame.Content == null) { // When the navigation stack isn't restored navigate to the first page. rootFrame.Navigate(typeof(MainPage), e.Arguments); } // Place the main page in the current Window. Window.Current.Content = rootPage; } // Ensure the current window is active Window.Current.Activate(); }
public NavigationRootPage() { this.InitializeComponent(); // LoadGroups(); Current = this; RootFrame = rootFrame; Loaded += NavigationRootPage_Loaded; //Use the hardware back button instead of showing the back button in the page if (ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons")) { Windows.Phone.UI.Input.HardwareButtons.BackPressed += (s, e) => { if (rootFrame.CanGoBack) { rootFrame.GoBack(); e.Handled = true; } }; } }