Ejemplo n.º 1
0
        // Called when a KeyDownTarget is specified and a KeyDown event is detected on the source
        private static void OnKeyDownTargetKeyDown(object sender, KeyEventArgs e)
        {
            // Ignore handled events
            if (e.Handled)
            {
                return;
            }

            // Ignore navigation keys
            if (e.Key == Key.Left || e.Key == Key.Right || e.Key == Key.Up || e.Key == Key.Down ||
                e.Key == Key.Tab || e.Key == Key.Escape || e.Key == Key.Return || e.Key == Key.Enter ||
                e.Key == Key.PageUp || e.Key == Key.PageDown || e.Key == Key.Home || e.Key == Key.End || e.Key == Key.LeftCtrl || e.Key == Key.RightCtrl)
            {
                return;
            }

            if (Keyboard.Modifiers == ModifierKeys.Control)
            {
                return;
            }



            DependencyObject keySender = sender as DependencyObject;

            Fx.Assert(keySender != null, "keySender should not be null");
            if (keySender == null)
            {
                return;
            }

            FrameworkElement keyTarget = GetKeyDownTarget(keySender);

            Fx.Assert(keyTarget != null, "keyTarget should not be null");
            if (keyTarget == null)
            {
                return;
            }

            // Find a focusable element on the target, set focus to it, and send the keys over
            FrameworkElement focusable = VisualTreeUtils.FindFocusableElement <FrameworkElement>(keyTarget);

            if (focusable != null && focusable == Keyboard.Focus(focusable))
            {
                focusable.RaiseEvent(e);
            }
        }