C# 转到TabControl wpf的下一个tabitem

C# 转到TabControl wpf的下一个tabitem,c#,wpf,C#,Wpf,我有一个带有树TabItems的TabControl。我在每个选项卡项中都有多个元素。在当前选项卡项的最后一个元素上按enter键时,我想转到下一个选项卡项 我使用enter键输入每个元素。 当按下enter键时,如何转到下一个选项卡项?为什么不在每个TabItem中为最后一个文本框添加PreviewKeyDown处理程序,然后在按下enter键时切换到下一个TabItem: <TextBox Text="{Binding SomeValue}" PreviewKeyDown="TextB

我有一个带有树TabItems的TabControl。我在每个选项卡项中都有多个元素。在当前选项卡项的最后一个元素上按enter键时,我想转到下一个选项卡项

我使用enter键输入每个元素。
当按下enter键时,如何转到下一个选项卡项?

为什么不在每个
TabItem
中为最后一个
文本框添加
PreviewKeyDown
处理程序,然后在按下
enter
键时切换到下一个
TabItem

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

private void TextBox\u PreviewKeyDown(对象发送方,KeyEventArgs e)
{
如果(e.Key==Key.Enter | | e.Key==Key.Return)
{
YourTabControl.SelectedIndex=YourTabControl.SelectedIndex<
YourTabControl.Items.Count-1?YourTabControl.SelectedIndex+1:0;
}
}

您可以发布您已经尝试过的代码吗?您可以尝试以下答案中的解决方案:谢谢,两个选项卡都可以,但当我添加malty选项卡时,不要在第二个选项卡中引发控制事件:(
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;
    }
}