What is the difference between TabIndex
and KeyboardNavigation.TabIndex
in WPF? When to use each?
@akjoshi included a very important piece of information about TabIndex in his answer but I thought a little more explanation would help.
If you have an ItemsControl
repeating an item you will end up with a tab order like this if you're not careful.
The solution is simple :
Apply this attached property to the main container of each repeated item.
KeyboardNavigation.TabNavigation="Local"
This enumeration has all kinds of values, but this is the one to use for nested controls.
Note I've set IsTabStop=false
for the ItemsControl
itself (and no this isn't the actualy code for the graphic above).
<ItemsControl ItemsSource="{Binding CurrentItem.CustomsItems}" IsTabStop="False">
<ItemsControl.ItemTemplate>
<DataTemplate>
<ctl:CustomsItem KeyboardNavigation.TabNavigation="Local" Margin="0,0,0,8"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>