首页 > 代码库 > WPF 回车转Tab实现跳转
WPF 回车转Tab实现跳转
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; } }
WPF 回车转Tab实现跳转
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。