Setting tab order in WPF

.NetWpfTab OrderingKeyboard Navigation

.Net Problem Overview


How do I set tab ordering in WPF? I have an ItemsControl with some items expanded and some collapsed and would like to skip the collapsed ones when I'm tabbing.

Any ideas?

.Net Solutions


Solution 1 - .Net

If you want to explicitly set the tab ordering for elements in your form, the following attached property is supposed to help:

<Control KeyboardNavigation.TabIndex="0" ... />

I say "supposed to help" as I haven't found it very reliable though I probably need to read more about how it is intended to be used. I only post this half baked answer because no one else mentioned this property.


Note that in Win RT, the property is just TabIndex="0".

Solution 2 - .Net

You can skip elements in the tab sequence by setting KeyboardNavigation.IsTabStop on the element in XAML.

KeyboardNavigation.IsTabStop="False"

You can setup a trigger that would toggle this property based on the expanded state.

Solution 3 - .Net

<Control KeyboardNavigation.TabIndex="0" ... /> Works perfectly fine... For example-

<ComboBox Height="23" 
          Margin="148,24,78,0" 
          Name="comboBoxDataSet"
          VerticalAlignment="Top"
          SelectionChanged="comboBoxDestMarketDataSet_SelectionChanged"
          DropDownOpened="comboBoxDestMarketDataSet_DropDownOpened"
          KeyboardNavigation.TabIndex="0" />
<ComboBox Height="23" 
          Margin="148,56,78,0" 
          Name="comboBoxCategory" 
          VerticalAlignment="Top" 
          SelectionChanged="comboBoxDestCategory_SelectionChanged"
          DropDownOpened="comboBoxDestCategory_DropDownOpened"
          KeyboardNavigation.TabIndex="1" />

Will allow you to navigate through these two combo boxes using TAB key.

Solution 4 - .Net

I think there is a much easier solution here, at the top within your control or window or whatever, you could add:

KeyboardNavigation.TabNavigation="Cycle"

This also automaticaly ignores the collapsed tabs.

Solution 5 - .Net

Another alternative that has worked for me in the past is to simply remove all explicit TabIndex statements, and let the controls use the order that they're declared in XAML work their magic.

This, of course, may require you to reorder your controls. But this is a simple copy-paste operation.

Solution 6 - .Net

You can use KeyboardNavigation.TabNavigation="None" to completely skip the Tabbing for specific control.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRom&#225;nView Question on Stackoverflow
Solution 1 - .NetDrew NoakesView Answer on Stackoverflow
Solution 2 - .NetJabView Answer on Stackoverflow
Solution 3 - .NetPankajView Answer on Stackoverflow
Solution 4 - .NetAltF4_View Answer on Stackoverflow
Solution 5 - .NetGustavo MoriView Answer on Stackoverflow
Solution 6 - .Netuser2306815View Answer on Stackoverflow