Example #1
0
        public NavigationService(Frame frame)
        {
            FrameFacade             = new FrameFacade(frame);
            FrameFacade.Navigating += async(s, e) =>
            {
                if (e.Suspending)
                {
                    return;
                }

                // allow the viewmodel to cancel navigation
                e.Cancel = !NavigatingFrom(false);
                if (!e.Cancel)
                {
                    await NavigateFromAsync(false);
                }
            };
            FrameFacade.Navigated += (s, e) =>
            {
                NavigateTo(e.NavigationMode, e.Parameter);
            };
        }
Example #2
0
        public bool Navigate(Type page, object parameter = null, NavigationTransitionInfo infoOverride = null)
        {
            if (page == null)
            {
                throw new ArgumentNullException(nameof(page));
            }
            if (page.FullName.Equals(LastNavigationType))
            {
                if (parameter == LastNavigationParameter)
                {
                    return(false);
                }

                if (parameter != null && parameter.Equals(LastNavigationParameter))
                {
                    return(false);
                }
            }

            parameter = SerializePageParam(parameter);
            return(FrameFacade.Navigate(page, parameter, infoOverride));
        }
Example #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);
                }
            }
        }
Example #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); }
        }
Example #5
0
 public void GoForward()
 {
     FrameFacade.GoForward();
 }
Example #6
0
 public void Refresh()
 {
     FrameFacade.Refresh();
 }