首页 > Windows开发 > 详细

WPF 窗体基类实现的体验及实现回车到下一控件

时间:2018-11-07 22:51:51      阅读:263      评论:0      收藏:0      [点我收藏+]
原文:WPF 窗体基类实现的体验及实现回车到下一控件

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jsyhello/article/details/7216509

1、窗体基类实现参考

http://weblogs.asp.net/psheriff/archive/2009/11/02/creating-a-base-window-class-in-wpf.aspx

2、基类不能像WinForm窗体一样写Loaded事件(写了也是不执行的)

没办法只好写一个方法让所有继承者调用了

3、回车键改为TAB的实现

??????? /// <summary>
??????? /// 将回车改为TAB
??????? /// </summary>
??????? /// <param name="e"></param>
??????? protected override void OnKeyDown(System.Windows.Input.KeyEventArgs e)
??????? {
??????????? if (e.Key == System.Windows.Input.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);
??????? }


欢迎访问:http://121.18.78.216 适易查询分析、工作流、内容管理及项目管理演示平台

WPF 窗体基类实现的体验及实现回车到下一控件

原文:https://www.cnblogs.com/lonelyxmas/p/9926158.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!