如何在WPF中使用键盘快捷键? [英] How do I work with keyboard shortcuts in WPF?

查看:85
本文介绍了如何在WPF中使用键盘快捷键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有10个复选框项目,按字母顺序排列,例如:

I have 10 check box items sorted alphabetically, say for example:

Apple,AirCraft,Ball,Bottom,Cat等

通过按 A 键,必须将焦点设置为 Apple 复选框,将 B -设置为 Ball >.我怎样才能做到这一点?这些复选框项目由于项目来源计数而动态可变.

By pressing the A key the focus must be set to the Apple check box, B - to Ball. How can I do this? These check box items are dynamically variable due to the item source count.

我想,因为复选框项目未在XAML中进行硬编码,所以我无法标记;我在运行时加载它们.如果我有类似以下的内容怎么办?

Since checkbox items are not hardcoded in XAML I cannot tag, I guess; I load them during run time. And what if I have items like the following?

  1. 苹果
  2. Apple1
  3. Apple2
  1. Apple
  2. Apple1
  3. Apple2

在这种情况下,我无法设置快捷方式的正确性,因此,如果我按 A ,则第一个以字母 A 开头的项目将获得焦点,然后再次按 A ,将焦点设置为以字母 A 开头的下一项.如果到达最后一个以字母 A 开头的项目,那么再次按 A 则必须转到第一个以字母 A 开头的项目>,所以这是我的要求:).我该怎么办?

In this scenario I can't set the shortcut right, so instead, if I press A the first item that starts with letter A will get focus and again pressing A, focus set to the next item that starts with letter A. If it reaches the last item that starts with letter A then again if I press A it has to go to the first item that has starting letter A, so this is my requirement:). How can I do this?

推荐答案

您可以使用键盘导航,方法是先按alt键,然后将复选框的内容设置为:

You can use the keyboard navigation by first pressing the alt key, and setting the check boxes content as:

<CheckBox Content="_Apple" />
<CheckBox Content="_Ball" />

请记住,相关的键盘快捷键将是"_"符号后的快捷键.

Keep in mind that the associated keyboard shortcut will be the one after the "_" symbol.

这篇关于如何在WPF中使用键盘快捷键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆