Manipulating tab order and focus

The Tab key in a typical user interface can be used to move the keyboard focus from one control to another (with Shift + Tab working in the reverse order), providing keyboard navigation capabilities without the need to use the mouse. This has to be logical – that is, the focus should not jump erratically all over the place, but rather move to the next logical control within the UI. The following recipe shows how to set the tab order and how to set the focus to a given control.

Getting ready

Make sure Visual Studio is up and running.

How to do it…

We'll create a personal information entry form that uses tab order in a logical manner, and places the keyboard focus where it makes sense when the form first appears:

Get Windows Presentation Foundation 4.5 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.