用所有控件放在Grid border 等等容器里,然后再定义其下所有元素的PreviewKeyDown事件:
PreviewKeyDown="grid_main_PreviewKeyDown"
-
private void Grid_PreviewKeyDown(object sender, KeyEventArgs e)
-
{
-
var uie = e.OriginalSource as UIElement;
-
if (e.Key == Key.Enter)
-
{
-
e.Handled = true;
-
uie.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
-
}
-
}
作用于窗口所有控件的话,定义Window_KeyDown事件。