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

推荐订阅源

GbyAI
GbyAI
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
D
Docker
Blog — PlanetScale
Blog — PlanetScale
罗磊的独立博客
美团技术团队
V
V2EX
Last Week in AI
Last Week in AI
D
DataBreaches.Net
T
The Blog of Author Tim Ferriss
宝玉的分享
宝玉的分享
Microsoft Security Blog
Microsoft Security Blog
Microsoft Azure Blog
Microsoft Azure Blog
人人都是产品经理
人人都是产品经理
M
MIT News - Artificial intelligence
P
Proofpoint News Feed
B
Blog RSS Feed
博客园_首页
B
Blog
博客园 - 叶小钗
I
InfoQ
WordPress大学
WordPress大学
L
LangChain Blog
Apple Machine Learning Research
Apple Machine Learning Research
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
A
About on SuperTechFans
The GitHub Blog
The GitHub Blog
The Register - Security
The Register - Security
MyScale Blog
MyScale Blog
云风的 BLOG
云风的 BLOG
博客园 - 司徒正美
Latest news
Latest news
W
WeLiveSecurity
T
The Exploit Database - CXSecurity.com
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
aimingoo的专栏
aimingoo的专栏
小众软件
小众软件
Cyberwarzone
Cyberwarzone
Scott Helme
Scott Helme
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CERT Recently Published Vulnerability Notes
C
CXSECURITY Database RSS Feed - CXSecurity.com
Recent Commits to openclaw:main
Recent Commits to openclaw:main
N
News and Events Feed by Topic
S
Secure Thoughts
The Hacker News
The Hacker News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News

博客园 - 流泉飞石

转: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)  评论()    收藏  举报