Example #1
0
 public Shell(NavigationService navigationService)
 {
     Instance = this;
     InitializeComponent();
     Window = WindowWrapper.Current();
     MyHamburgerMenu.NavigationService = navigationService;
     VisualStateManager.GoToState(Instance, Instance.NormalVisualState.Name, true);
 }
Example #2
0
        public Shell(INavigationService navigationService)
        {
            Instance = this;
            this.InitializeComponent();

            // setup for static calls
            Window = WindowWrapper.Current();
            MyHamburgerMenu.NavigationService = navigationService;

            // any nav change, reset to normal
            navigationService.FrameFacade.Navigated += (s, e) =>
                BusyModal.IsModal = SearchModal.IsModal = LoginModal.IsModal = false;
        }
Example #3
0
        /// <summary>
        /// Craetes a new FamFrame and adds the resulting NavigationService to the
        /// WindowWrapper collection. In addition, it optionally will setup the
        /// shell back button to react to the nav of the Frame.
        /// A developer should call this when creating a new/secondary frame.
        /// The shell back button should only be setup one time.
        /// </summary>
        public Services.NavigationService.NavigationService NavigationServiceFactory(BackButton backButton, ExistingContent existingContent)
        {
            var frame = new Frame
            {
                Language = Windows.Globalization.ApplicationLanguages.Languages[0],
                Content  = (existingContent == ExistingContent.Include) ? Window.Current.Content : null,
            };

            var navigationService = new Services.NavigationService.NavigationService(frame);

            navigationService.FrameFacade.BackButtonHandling = backButton;
            WindowWrapper.Current().NavigationServices.Add(navigationService);

            if (backButton == BackButton.Attach)
            {
                // TODO: unattach others

                // update shell back when backstack changes
                // only the default frame in this case because secondary should not dismiss the app
                frame.RegisterPropertyChangedCallback(Frame.BackStackDepthProperty, (s, args) => UpdateShellBackButton());

                // update shell back when navigation occurs
                // only the default frame in this case because secondary should not dismiss the app
                frame.Navigated += (s, args) => UpdateShellBackButton();
            }

            // this is always okay to check, default or not
            // expire any state (based on expiry)
            DateTime cacheDate;
            // default the cache age to very fresh if not known
            var otherwise = DateTime.MinValue.ToString();

            if (DateTime.TryParse(navigationService.FrameFacade.GetFrameState(CacheDateKey, otherwise), out cacheDate))
            {
                var cacheAge = DateTime.Now.Subtract(cacheDate);
                if (cacheAge >= CacheMaxDuration)
                {
                    // clear state in every nav service in every view
                    foreach (var service in WindowWrapper.ActiveWrappers.SelectMany(x => x.NavigationServices))
                    {
                        service.FrameFacade.ClearFrameState();
                    }
                }
            }
            else
            {
                // no date, that's okay
            }

            return(navigationService);
        }
Example #4
0
        protected sealed override void OnWindowCreated(WindowCreatedEventArgs args)
        {
            DebugWrite();

            if (!WindowWrapper.ActiveWrappers.Any())
            {
                Loaded();
            }

            // handle window
            var window = new WindowWrapper(args.Window);

            WindowCreated?.Invoke(this, args);
            base.OnWindowCreated(args);
        }
Example #5
0
        protected sealed override void OnWindowCreated(WindowCreatedEventArgs args)
        {
            DebugWrite();
            //should be called to initialize and set new SynchronizationContext
            if (!WindowWrapper.ActiveWrappers.Any())
            {
                Loaded();
            }
            // handle window
            var window = new WindowWrapper(args.Window);

            ViewService.OnWindowCreated();
            WindowCreated?.Invoke(this, args);
            base.OnWindowCreated(args);
        }
        private void RaiseForwardRequested()
        {
            var args = new HandledEventArgs();

            foreach (var frame in WindowWrapper.Current().NavigationServices.Select(x => x.FrameFacade))
            {
                frame.RaiseForwardRequested(args);
                if (args.Handled)
                {
                    return;
                }
            }

            // default to first window
            NavigationService.GoForward();
        }
        /// <summary>
        /// Default Hardware/Shell Back handler overrides standard Back behavior
        /// that navigates to previous app in the app stack to instead cause a backward page navigation.
        /// Views or Viewodels can override this behavior by handling the BackRequested
        /// event and setting the Handled property of the BackRequestedEventArgs to true.
        /// </summary>
        private void RaiseBackRequested(ref bool handled)
        {
            var args = new HandledEventArgs();

            foreach (var frame in WindowWrapper.Current().NavigationServices.Select(x => x.FrameFacade).Reverse())
            {
                frame.RaiseBackRequested(args);
                handled = args.Handled;
                if (handled)
                {
                    return;
                }
            }

            // default to first window
            NavigationService.GoBack();
        }
Example #8
0
        private void RaiseForwardRequested()
        {
            var args = new HandledEventArgs();

            ForwardRequested?.Invoke(null, args);
            if (args.Handled)
            {
                return;
            }
            foreach (var frame in WindowWrapper.Current().NavigationServices.Select(x => x.FrameFacade))
            {
                frame.RaiseForwardRequested(args);
                if (args.Handled)
                {
                    return;
                }
            }
            NavigationService.GoForward();
        }
Example #9
0
        /// <summary>
        /// Default Hardware/Shell Back handler overrides standard Back behavior
        /// that navigates to previous app in the app stack to instead cause a backward page navigation.
        /// Views or Viewodels can override this behavior by handling the BackRequested
        /// event and setting the Handled property of the BackRequestedEventArgs to true.
        /// </summary>
        private void RaiseBackRequested(ref bool handled)
        {
            var args = new HandledEventArgs();

            BackRequested?.Invoke(null, args);
            if (handled = args.Handled)
            {
                return;
            }
            foreach (var frame in WindowWrapper.Current().NavigationServices.Select(x => x.FrameFacade).Reverse())
            {
                frame.RaiseBackRequested(args);
                if (handled = args.Handled)
                {
                    return;
                }
            }
            NavigationService.GoBack();
        }
Example #10
0
        private void RaiseForwardRequested()
        {
            DebugWrite();

            var args = new HandledEventArgs();

            ForwardRequested?.Invoke(null, args);
            if (args.Handled)
            {
                return;
            }
            foreach (var navigationService in WindowWrapper.Current().NavigationServices)
            {
                navigationService.RaiseForwardRequested(args);
                if (args.Handled)
                {
                    return;
                }
            }
            NavigationService.GoForward();
        }
Example #11
0
        private void RaiseBackRequested(ref bool handled)
        {
            DebugWrite();

            var args = new HandledEventArgs();

            BackRequested?.Invoke(null, args);
            if (handled = args.Handled)
            {
                return;
            }
            foreach (var navigationService in WindowWrapper.Current().NavigationServices.Select(x => x).Reverse())
            {
                navigationService.RaiseBackRequested(args);
                if (handled = args.Handled)
                {
                    return;
                }
            }
            NavigationService.GoBack();
            handled = true;
        }
 public static IDispatcherWrapper Current() => WindowWrapper.Current().Dispatcher;
Example #13
0
 protected override void OnWindowCreated(WindowCreatedEventArgs args)
 {
     var window = new WindowWrapper(args.Window);
     WindowCreated?.Invoke(this, args);
     base.OnWindowCreated(args);
 }
Example #14
0
        // this is private because there's no reason for the developer to call this
        private Frame InitializeFrame(ILaunchActivatedEventArgs e)
        {
            // do not recreate the frame
            if (Window.Current.Content is Frame)
            {
                return(Window.Current.Content as Frame);
            }

            // first show the splash
            var splashScreen = default(UIElement);

            if (SplashFactory != null)
            {
                splashScreen           = SplashFactory(e.SplashScreen);
                Window.Current.Content = splashScreen;
                Window.Current.Activate();
            }
            else
            {
                // if there is no SplashScreen then the default/static splash will show.
            }

            // in any case, next create a new, default frame
            var defaultFrame = new Frame
            {
                Language = Windows.Globalization.ApplicationLanguages.Languages[0]
            };

            // set default frame as primary, default visual
            Window.Current.Content = defaultFrame;

            // next setup the default view
            var navigationService = new Services.NavigationService.NavigationService(defaultFrame);

            WindowWrapper.Current().NavigationServices.Add(navigationService);

            // this anon method will be used to refresh the shell back button
            Action updateShellBack = () =>
            {
                // show the shell back only if there is anywhere to go in the default frame
                SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
                    (ShowShellBackButton && NavigationService.Frame.CanGoBack)
                        ? AppViewBackButtonVisibility.Visible
                        : AppViewBackButtonVisibility.Collapsed;
            };

            // update shell back when backstack changes
            // only the default frame in this case because secondary should not dismiss the app
            defaultFrame.RegisterPropertyChangedCallback(Frame.BackStackDepthProperty, (s, args) => updateShellBack());

            // update shell back when navigation occurs
            // only the default frame in this case because secondary should not dismiss the app
            defaultFrame.Navigated += (s, args) => updateShellBack();

            // expire any state (based on expiry)
            DateTime cacheDate;
            // default the cache age to very fresh if not known
            var otherwise = DateTime.MinValue.ToString();

            if (DateTime.TryParse(navigationService.FrameFacade.GetFrameState(CacheDateKey, otherwise), out cacheDate))
            {
                var cacheAge = DateTime.Now.Subtract(cacheDate);
                if (cacheAge >= CacheMaxDuration)
                {
                    // clear state in every nav service in every view
                    foreach (var service in WindowWrapper.ActiveWrappers.SelectMany(x => x.NavigationServices))
                    {
                        service.FrameFacade.ClearFrameState();
                    }
                }
            }
            else
            {
                // no date, that's okay
            }

            // finally return our new frame
            return(defaultFrame);
        }