pavanpodila
pavanpodila

Reputation: 76

How does WPF build up the list of controls that can be tab-navigated?

I am curious to know how WPF figures out where the focus should be set when the user hits the TAB key. Thinking aloud, I feel:

  1. It may be doing relative search on the UI and find the nearest control based on (x,y) location.
  2. It could manually walk the logical sub-tree to look for the nearest control

Does it do it each time the TAB key is pressed ?

Upvotes: 1

Views: 171

Answers (1)

Wonko the Sane
Wonko the Sane

Reputation: 10823

From WPFWiki:

Tab Navigation moves the focus through controls in a logical sequence.

The default logical sequence is that controls will be focused starting from the first focusable child of the root control (window, page, etc.). From that point, the TabNavigation property is considered, and the next control in sequence is either the first focusable descendent of the currently focused control or the next focusable sibling. The TabNavigation property of the newly focused control is then evaluated, and so on.

For the most part, the tab order (using the rule described above) will generally be from the top of your XAML file to the bottom.

Of course, this can be modified by setting KeyboardNavigation attached properties, such as IsTabStop, TabNavigation, TabIndex, etc.

Perhaps not the most technical answer (I don't know the actual guts of it), but that's the general idea...

Upvotes: 1

Related Questions