tags:

views:

37

answers:

1

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 ?

A: 

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...

Wonko the Sane
I knew about the TabNavigation and keyboardNavigation options. However I was interested in how WPF builds the set of controls that can be reached from the current control. Does it do it once at load or each time the TAB key is pressed. I think there are several properties that WPF need to consider to determine the next control in the traversal order.I want to know the guts since I am building something to enhance the keyboard navigation in our app.
pavanpodila
I wish I could give you more information on that, but I don't know. The only comment I have is to be careful about too much "navigation enhancement" - users like things to be predictable, and to behave in ways consistent from application to application.
Wonko the Sane