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

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

问题描述

目前我有一个带有自定义 UserControl 的 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 UserControl 吗?

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.

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

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