/// <summary> /// Creates a NavigationService instance. /// </summary> /// <param name="frame">The page frame.</param> internal NavigationService(Frame frame) { try { FrameFacade = new FrameFacade(frame); FrameFacade.Navigated += (s, e) => { if (e.PageType == UniversalApp.Current.DefaultPage) { ClearHistory(); } // KEEP THIS EVENT REGISTERED: without having this empty event registered, for whatever reason no navigation takes place // Navigation method calls are moved to UniversalPage, to ensure the call order of ViewModel navigation events is aligned // with the one of a Page. }; } catch (Exception) { // exception in ShareTarget here. } }
/// <summary> /// Save the navigation state. /// </summary> public void SaveNavigation() { // it is possible to close the application before we have navigated and created state if (CurrentPageType == null) { return; } var state = FrameFacade.GetPageStateContainer(GetType()); if (state == null) { throw new InvalidOperationException("State container is unexpectedly null"); } state[CURRENT_PAGE_TYPE_KEY] = CurrentPageType.ToString(); try { state[CURRENT_PAGE_PARAM_KEY] = CurrentPageParam; } catch { throw new Exception("Failed to serialize page parameter, override/implement ToString()"); } state[NAVIGATE_STATE_KEY] = FrameFacade?.GetNavigationState(); }