Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting tab order in WPF

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?

like image 583
Román Avatar asked Dec 11 '08 15:12

Román


People also ask

How to set tab order in c# WPF?

Pressing the tab key moves the focus between controls. The tab order determines in which order items are visited when pressing tab. The order is reversed if the user holds the Shift key whilst tapping tab. The default tab order for a window is determined by the position of each control within the logical tree.

What is TabIndex WPF?

TabIndex is used to define the order, while the IsTabStop property will force WPF to skip a control when tabbing through the Window.

What is TabIndex C#?

TabIndex is important for controls which are siblings of the same parent. However, if your TextBox and ComboBox controls are each inside different parents then their parent controls must have a the proper TabIndex.


2 Answers

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

like image 84
Drew Noakes Avatar answered Sep 21 '22 07:09

Drew Noakes


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.

like image 24
Jab Avatar answered Sep 19 '22 07:09

Jab