0
votes

Im using WPF and C#. I have an application with an OnScreenKeyboard made with buttons. When I press the tab button in the OnScreenKeyboard it does this:

if (IsEnterEnabled){
  CurrentTextBox.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
}

CurrentTextBox is a Control.

When a textbox is focused it works fine and move to the next focus, even if the next focus is a comboBox, but if the current focus is in an editable combo box it doesnt move to next focus element.

If the combo box is not editable, it works.

2
Did you check to see if that control can have focus? and is selectable / able to be tabbed to? - tcables
Yes, if I press the tab key in my real keyboard it works fine. - davibq

2 Answers

0
votes

Since the ComboBox has a TextBox inside it which currently has focus, telling ComboBox to move next will only move to the TextBox. Instead, get the inner TextBox and move next on that:

        var s1 = FocusManager.GetFocusedElement(this);
        if (s1 is FrameworkElement)
        {
            ((FrameworkElement)s1).MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
        }
0
votes

You can use my EnterKeyTraversal attached property code if you like. Add it to the top-level container on a WPF window and everything inside will treat enter as tab:

<ComboBox my:EnterKeyTraversal.IsEnabled="True">
...
</ComboBox>