예제 #1
0
        private void Frame_BackKeyPress(object s, CancelEventArgs e)
        {
            var eventArgs = new NavigationServiceBackKeyPressedEventArgs();

            RaiseBackKeyPressed(eventArgs);

            switch (eventArgs.Behavior)
            {
            case NavigationServiceBackKeyPressedBehavior.GoBack:
                break;

            case NavigationServiceBackKeyPressedBehavior.HideApp:
                ExceptionHelper.ThrowNotSupported();
                break;

            case NavigationServiceBackKeyPressedBehavior.ExitApp:
                e.Cancel = true;
                Application.Current.Terminate();
                break;

            case NavigationServiceBackKeyPressedBehavior.DoNothing:
                e.Cancel = true;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        /// <summary>
        /// Raises the <see cref="BackKeyPressed"/> event with the provided event data.
        /// </summary>
        /// <param name="eventArgs">The event data.</param>
        protected virtual void RaiseBackKeyPressed(NavigationServiceBackKeyPressedEventArgs eventArgs)
        {
            var eventHandler = BackKeyPressed;

            if (eventHandler != null)
            {
                eventHandler(this, eventArgs);
            }
        }
        private bool HandleBackKeyPress()
        {
            var handled = GetMasterDetailView()?.HandleBackKeyPress() ?? false;

            if (!handled)
            {
                var eventArgs = new NavigationServiceBackKeyPressedEventArgs();

                RaiseBackKeyPressed(eventArgs);

                switch (eventArgs.Behavior)
                {
                case NavigationServiceBackKeyPressedBehavior.GoBack:
                    var frame = GetFrame();

                    if (frame?.CanGoBack ?? false)
                    {
                        frame.GoBack();
                        handled = true;
                    }
                    break;

                case NavigationServiceBackKeyPressedBehavior.HideApp:
                    break;

                case NavigationServiceBackKeyPressedBehavior.ExitApp:
                    handled = true;
                    Application.Current?.Exit();
                    break;

                case NavigationServiceBackKeyPressedBehavior.DoNothing:
                    handled = true;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            return(handled);
        }
예제 #4
0
 /// <summary>
 /// Raises the <see cref="BackKeyPressed"/> event with the provided event data.
 /// </summary>
 /// <param name="eventArgs">The event data.</param>
 protected virtual void RaiseBackKeyPressed(NavigationServiceBackKeyPressedEventArgs eventArgs)
 {
     BackKeyPressed?.Invoke(this, eventArgs);
 }
예제 #5
0
 private void NavigationServiceOnBackKeyPressed(object sender, NavigationServiceBackKeyPressedEventArgs e)
 {
     e.Behavior = NavigationServiceBackKeyPressedBehavior.GoBack;
 }