惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
SegmentFault 最新的问题
G
Google Developers Blog
H
Help Net Security
月光博客
月光博客
阮一峰的网络日志
阮一峰的网络日志
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Proofpoint News Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
B
Blog RSS Feed
爱范儿
爱范儿
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 三生石上(FineUI控件)
大猫的无限游戏
大猫的无限游戏
人人都是产品经理
人人都是产品经理
GbyAI
GbyAI
D
Docker
Hugging Face - Blog
Hugging Face - Blog
I
InfoQ
博客园 - 司徒正美
Last Week in AI
Last Week in AI
Microsoft Security Blog
Microsoft Security Blog
美团技术团队
Stack Overflow Blog
Stack Overflow Blog
M
MIT News - Artificial intelligence

博客园 - 流泉飞石

转:ADO.Net Entity Framework : (七) 多條件查詢 转载:GridView 空记录时显示 Header 代码重构相关书籍 转:恢复Reflector反编译后资源文件的办法 C#自定义快捷键实现介绍 C#程序多用户只启动一个进程的方法[转载] C#中自定义快捷键【转载】 转:[WPF] WPF资源收集 分享 转:.NET开发人员必知的八个网站 WatermarkComboBox 和 WatermarkTextBox 转:c#中线程访问winform控件的若干问题 [转] DotNet资源站点汇总 DataKeyNames工作 - 流泉飞石 - 博客园 转:功能很强大的UIHelper类 转:动态修改webservice地址 转:CS结构软件自动升级实现 几个很好的url重写工具 asp.net获取应用程序路径 - 流泉飞石 - 博客园 SqlServer 查询sql执行时间
WPF 回车转Tab实现跳转
流泉飞石 · 2010-01-29 · via 博客园 - 流泉飞石

1.重写窗体的KeyDown事件

Code Snippet

  1. protected override void OnKeyDown(KeyEventArgs e)
  2. {
  3.     if (e.Key == Key.Enter)
  4.     {
  5.         // MoveFocus takes a TraveralReqest as its argument.
  6.         TraversalRequest request = new TraversalRequest(FocusNavigationDirection.Next);
  7.  
  8.         // Gets the element with keyboard focus.
  9.         UIElement elementWithFocus = Keyboard.FocusedElement as UIElement;
  10.  
  11.         // Change keyboard focus.
  12.         if (elementWithFocus != null)
  13.         {
  14.             elementWithFocus.MoveFocus(request);
  15.         }
  16.         e.Handled = true;
  17.     }
  18.     base.OnKeyDown(e);
  19. }

2.在基容器如Grid的KeyDown事件中

Code Snippet

  1. <Grid KeyDown="Grid_KeyDown">

实现代码

Code Snippet

  1. private void Grid_KeyDown(object sender, KeyEventArgs e)
  2. {
  3.     var uie = e.OriginalSource as UIElement;
  4.     if (e.Key == Key.Enter)
  5.     {
  6.         uie.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
  7.         e.Handled = true;
  8.     }
  9. }

posted @ 2010-01-29 13:18  流泉飞石  阅读(2697)  评论()    收藏  举报