将选项卡顺序限制为单个用户控件 (WPF) [英] Restrict tab order to a single user control (WPF)

查看:9
本文介绍了将选项卡顺序限制为单个用户控件 (WPF)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我有一个带有自定义用户控件的 WPF 项目.此控件包含一个网格,其中包含多个表单类型元素(复选框、文本框、组合框等).该控件被设计为以表单的形式进行外观和操作,但它被放置在拖动画布中,这就是为什么它需要是 UserControl 而不是窗口的原因.

Currently I have a WPF project with a custom UserControl. This control contains a grid which houses multiple form type elements (checkboxes, textboxes, comboboxes, etc.). The control is designed to look and operate as a form, however it's being placed inside a drag canvas, which is why it needs to be a UserControl and not a window.

问题是元素之间的选项卡导航需要限制在这个控件中,所以当我在控件中的最后一个元素上点击Tab"键时,键盘会聚焦在控件中的第一个元素.目前,它超出了控制范围,进入了应用程序中的下一个可选项卡元素.

The issue is the tab navigation between elements needs to be restricted to this control, so when I hit the "Tab" key on the last element in the control, the keyboard focuses the first element in the control. Currently it goes outside the control to the next tabbable element within the application.

除了手动捕获关键事件之外,还有其他方法可以将选项卡导航限制为单个 WPF 用户控件吗?

Aside from capturing the key events manually, is there another way to restrict the tab navigation to a single WPF UserControl?

推荐答案

在你的用户控件上试试这个:

Try this on your user control:

KeyboardNavigation.TabNavigation="Cycle"

这将确保在到达用户控件中的最后一个元素时,下一次按 Tab 键将循环回到开头.请参阅 MSDN 了解更多信息.

This will ensure when the last element in the user control is reached, the next tab press will cycle back to the beginning. See the MSDN for more information.

这篇关于将选项卡顺序限制为单个用户控件 (WPF)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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