Why isn't my XAML following the TabOrder I specified?
I currently have:
<DockPanel>
<Grid DockPanel.Dock="Top">
<UserControl TabIndex="0">
<StackPanel Orientation="Horizontal">
<ComboBox />
<TextBox Text="Search Text" />
<Button Content="Search" />
</StackPanel>
</UserControl>
<ComboBox TabIndex="1" />
<Separator />
<TextBox TabIndex="3" Text="Save" />
<TextBox TabIndex="4" Text="Cancel" />
</Grid>
<Grid>
<ContentControl TabIndex="2" />
<Popup />
</Grid>
</DockPanel>
My TabOrder should go
- Search ComboBox
- Search Text
- Search Button
- Database ComboBox
- ContentControl
- Save Button
- Cancel Button
But instead it goes
- Search ComboBox
- Search Text
- Search Button
- ContentControl
- Database ComboBox
- Save Button
- Cancel Button
What do I have wrong with my TabOrder?
Edit
I found this SO answer which suggested making UserControl.IsTabStop="False"
, and binding it's Child control's TabIndex to UserControl.TabIndex
, which partially works.
My TabOrder is now
- Search ComboBox
- Search Text
- Search Button
- Database ComboBox
- Save Button
- Cancel Button
- ContentControl
Apparently by default, WPF reads all the controls, inside and outside UserControls, at the same tab level (unless specified otherwise). Since the controls inside the UserControl do not have a TabIndex specified, they get tabbed to last after the first tab cycle.
The workaround was to bind the
TabIndex
of the inner controls to theTabIndex
of the UserControlThe only thing special about my
SearchView
is that the controls all setTab Order goes: