2

I have a TabControl with tree TabItems. I have multiple elements in every TabItem. I want to go to the next TabItem when I press the enter key at the last element of the current TabItem.

I use EnterKeyTraversal attached property for enter key of every element. How do go to the next TabItem when the enter key were pressed?

Mirko Sbr
  • 92
  • 8
ar.gorgin
  • 4,765
  • 12
  • 61
  • 100
  • Can you post the code from what you have already tried? – Bijington Jun 02 '15 at 07:16
  • You can try solutions from these answers: http://stackoverflow.com/questions/7929646/how-to-programmaticaly-select-a-tabitem-in-wpf-tabcontrol/25960172#25960172 – voytek Jun 02 '15 at 07:31

1 Answers1

0

Why don't you just add a PreviewKeyDown handler for the last TextBox in each TabItem and then switch to the next TabItem if the Enter key is pressed?:

<TextBox Text="{Binding SomeValue}" PreviewKeyDown="TextBox_PreviewKeyDown" />

...

private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
{
    if (e.Key == Key.Enter || e.Key == Key.Return)
    {
        YourTabControl.SelectedIndex = YourTabControl.SelectedIndex < 
            YourTabControl.Items.Count - 1 ? YourTabControl.SelectedIndex + 1 : 0;
    }
}
Sheridan
  • 68,826
  • 24
  • 143
  • 183