예제 #1
0
        // after navigate
        async Task NavigateFromAsync(bool suspending)
        {
            var page = FrameFacade.Content as Page;

            if (page != null)
            {
                // 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);
                }
            }
        }
예제 #2
0
        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();
        }
예제 #3
0
        void NavigateTo(NavigationMode mode, object parameter)
        {
            parameter = DeserializePageParam(parameter);

            LastNavigationParameter = parameter;
            LastNavigationType      = FrameFacade.Content.GetType().FullName;

            if (mode == NavigationMode.New)
            {
                FrameFacade.ClearFrameState();
            }

            var page = FrameFacade.Content as Page;

            if (page != null)
            {
                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);
                }
            }
        }
예제 #4
0
        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); }
        }