views:

7316

answers:

4

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?

+8  A: 

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.

Jab
+3  A: 

Also .NET 3.0 has a class that automatically sets the tab order and you can override this based on sections of your form.

 (new TabOrderManager(this)).SetTabOrder(TabOrderManager.TabScheme.AcrossFirst);
Ironsides
+5  A: 

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.

Drew Noakes
The trick is to use TabIndex with various values of KeyboardNavigation.TabNavigation in the parent element. I find myself using "Local" TabNavigation most often. :)
Greg D
+2  A: 

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

Pankaj