WPF 中的 TabIndex 与 KeyboardNavigation.TabIndex
WPF 中的 TabIndex
和 KeyboardNavigation.TabIndex
有什么区别?何时分别使用?
What is the difference between TabIndex
and KeyboardNavigation.TabIndex
in WPF? When to use each?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
@akjoshi 在他的回答中包含了有关 TabIndex 的非常重要的信息,但我认为更多的解释会有所帮助。
如果您有一个
ItemsControl
重复一个项目,您最终会得到与 tab 顺序类似如果你不小心的话,就会出现这个。解决方案很简单:
将此附加属性应用于每个重复项目的主容器。
这个枚举具有各种值,但这是一个用于嵌套控件。
请注意,我已为
ItemsControl
本身设置了IsTabStop=false
(这不是上图的实际代码)。@akjoshi included a very important piece of information about TabIndex in his answer but I thought a little more explanation would help.
If you have an
ItemsControl
repeating an item you will end up with a tab order like this if you're not careful.The solution is simple :
Apply this attached property to the main container of each repeated item.
This enumeration has all kinds of values, but this is the one to use for nested controls.
Note I've set
IsTabStop=false
for theItemsControl
itself (and no this isn't the actualy code for the graphic above).某些控件(例如
CheckBox
)具有TabIndex
属性,但并非所有控件都具有此属性,但您可能希望它们具有焦点并参与焦点导航,附加属性KeyboardNavigation。在这种情况下可以使用 TabIndex
。此类控制的示例是超链接
除此之外KeyboardNavigation 类提供了许多其他功能来设置焦点导航,例如选项卡导航行为、KeyboardNavigationMode 等。
Some controls like
CheckBox
haveTabIndex
property but not all controls have this property, but you may want them to have focus and participate in focus navigation, attached propertyKeyboardNavigation.TabIndex
can be used on in such cases. An example of such control isHyperlink
Apart from this KeyboardNavigation class provides a lot other functionality to set focus navigation, like tab navigation behavior, KeyboardNavigationMode etc.