Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restrict tab order to a single user control (WPF)

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?

like image 285
flamebaud Avatar asked Aug 17 '12 12:08

flamebaud


1 Answers

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.

like image 117
Lukazoid Avatar answered Oct 29 '22 01:10

Lukazoid