我有一个带有树 TabItem 的 TabControl。我在每个 TabItem 中都有多个元素。我想在当前 TabItem 的最后一个元素处按回车键时转到下一个 TabItem。
我使用 EnterKeyTraversal attached property用于输入每个元素的键。 如何在按下回车键时转到下一个 TabItem?
最佳答案
为什么不为每个 TabItem
中的最后一个 TextBox
添加一个 PreviewKeyDown
处理程序,然后切换到下一个 TabItem
如果 Enter
键被按下?:
<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;
}
}
关于c# - 转到 TabControl wpf 的下一个 tabitem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30589262/