标签:blog io ar div cti log sp on new
1.重写窗体的KeyDown事件
protected override void OnKeyDown(KeyEventArgs e) { if (e.Key == Key.Enter) { // MoveFocus takes a TraveralReqest as its argument. TraversalRequest request = new TraversalRequest(FocusNavigationDirection.Next); // Gets the element with keyboard focus. UIElement elementWithFocus = Keyboard.FocusedElement as UIElement; // Change keyboard focus. if (elementWithFocus != null) { elementWithFocus.MoveFocus(request); } e.Handled = true; } base.OnKeyDown(e); }
2.在基容器如Grid的KeyDown事件中
private void Grid_KeyDown(object sender, KeyEventArgs e) { var uie = e.OriginalSource as UIElement; if (e.Key == Key.Enter) { uie.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next)); e.Handled = true; } }
标签:blog io ar div cti log sp on new
原文地址:http://www.cnblogs.com/babietongtianta/p/3947353.html