public bool RestoreSavedNavigation() { try { var state = FrameFacade.PageStateContainer(GetType()); if (state == null || !state.Any() || !state.ContainsKey("CurrentPageType")) { return(false); } FrameFacade.CurrentPageType = Type.GetType(state["CurrentPageType"].ToString()); FrameFacade.CurrentPageParam = DeserializePageParam(state["CurrentPageParam"]?.ToString()); FrameFacade.SetNavigationState(state["NavigateState"]?.ToString()); NavigateTo(NavigationMode.Refresh, FrameFacade.CurrentPageParam); while (Frame.Content == null) { Task.Yield().GetAwaiter().GetResult(); } AfterRestoreSavedNavigation?.Invoke(this, FrameFacade.CurrentPageType); return(true); } catch { return(false); } }
// after navigate private async Task NavigateFromAsync(bool suspending) { var page = FrameFacade.Content as Page; // call viewmodel var dataContext = page?.DataContext as INavigable; if (dataContext != null) { var pageState = FrameFacade.PageStateContainer(page.GetType()); await dataContext.OnSaveStateAsync(pageState, suspending); dataContext.OnSaveState(pageState, suspending); } }
private void NavigateTo(NavigationMode mode, object parameter) { parameter = DeserializePageParam(parameter as string); LastNavigationParameter = parameter; LastNavigationType = FrameFacade.Content.GetType().FullName; if (mode == NavigationMode.New) { FrameFacade.ClearFrameState(); } var page = FrameFacade.Content as Page; if (page == null) { return; } var insightsService = App.Current.Kernel.Resolve <IInsightsService>(); insightsService.TrackPageView(page.GetType().Name); if (page.DataContext == null) { // to support dependency injection, but keeping it optional. var viewmodel = BootStrapper.Current.ResolveForPage(page.GetType(), this); if (viewmodel != null) { page.DataContext = viewmodel; } } // call viewmodel var dataContext = page.DataContext as INavigable; if (dataContext != null) { // prepare for state load dataContext.NavigationService = this; dataContext.Dispatcher = WindowWrapper.Current(this)?.Dispatcher; dataContext.SessionState = BootStrapper.Current.SessionState; var pageState = FrameFacade.PageStateContainer(page.GetType()); dataContext.OnNavigatedTo(parameter, mode, pageState); } }
public void SaveNavigation() { if (CurrentPageType == null) { return; } var state = FrameFacade.PageStateContainer(GetType()); if (state == null) { throw new InvalidOperationException("State container is unexpectedly null"); } state["CurrentPageType"] = CurrentPageType.AssemblyQualifiedName; state["CurrentPageParam"] = SerializePageParam(CurrentPageParam); state["NavigateState"] = FrameFacade?.GetNavigationState(); }