Restrict tab order to a single user control (WPF)

百般思念 提交于 2020-01-11 09:41:28

问题


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.

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.

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


回答1:


Try this on your user control:

KeyboardNavigation.TabNavigation="Cycle"

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.



来源:https://stackoverflow.com/questions/12005723/restrict-tab-order-to-a-single-user-control-wpf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!