Ejemplo n.º 1
0
        /// <summary>
        /// Call this method in Loaded event as the event will be automatically deregistred when the FrameworkElement has been unloaded
        /// </summary>
        public static void RegisterBackKey(Page page)
        {
            var callback = new TypedEventHandler <CoreDispatcher, AcceleratorKeyEventArgs>(
                delegate(CoreDispatcher sender, AcceleratorKeyEventArgs args)
            {
                if (!args.Handled && args.VirtualKey == VirtualKey.Back && args.EventType == CoreAcceleratorKeyEventType.KeyUp)
                {
                    var element = FocusManager.GetFocusedElement();
                    if (element is TextBox || element is PasswordBox || element is WebView)
                    {
                        return;
                    }

                    if (page.Frame.CanGoBack)
                    {
                        page.Frame.GoBack();
                    }
                }
            });

            page.Dispatcher.AcceleratorKeyActivated += callback;

            SingleEvent.Register(page,
                                 (p, h) => p.Unloaded += h,
                                 (p, h) => p.Unloaded -= h,
                                 (o, a) => { page.Dispatcher.AcceleratorKeyActivated -= callback; });
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Call this method in Loaded event as the event will be automatically deregistred when the FrameworkElement has been unloaded
 /// </summary>
 /// <param name="page"></param>
 /// <param name="handler"></param>
 public static void RegisterAcceleratorKeyActivated(FrameworkElement page, TypedEventHandler <CoreDispatcher, AcceleratorKeyEventArgs> handler)
 {
     page.Dispatcher.AcceleratorKeyActivated         += handler;
     SingleEvent.Register(page, (p, h) => p.Unloaded += h, (p, h) => p.Unloaded -= h, (o, a) =>
     {
         page.Dispatcher.AcceleratorKeyActivated -= handler;
     });
 }