0
votes

I have a WPF Application hostet in a WinForms ElementHost. When a diacritic character (e.g. "^" or "`") is entered in a Textbox, NOT followed by a literal, changing focus by pressing TAB does not work. A literal character must be typed first to make TAB work again.

In a native WPF application the diacritic gets displayed in the TextBox when pressing TAB, further presses of TAB change focus. The ElementHost seems to inhibit this behavior.

Any Ideas?

1

1 Answers

0
votes

A Workaround has been found by overriding OnKeyDown Method and checking e.DeadCharProcessedKey.

    protected override void OnPreviewKeyDown(KeyEventArgs e)
    {
        if (e.DeadCharProcessedKey == Key.Tab)
        {
            _ChangeFocus(e);
            e.Handled = true;
        }
        else
        {
            base.OnPreviewKeyDown(e);
        }
    }

    private static void _ChangeFocus(KeyEventArgs e)
    {
        var direction = Keyboard.Modifiers == ModifierKeys.Shift ? FocusNavigationDirection.Previous : FocusNavigationDirection.Next;
        var focusedElement = Keyboard.FocusedElement as UIElement;

        if (focusedElement != null && focusedElement .MoveFocus(new TraversalRequest(direction)))
            e.Handled = true;
    }