I have a DockPanel set up in the DataTemplate of an ItemsControl as below:
<ItemsControl HorizontalContentAlignment="Stretch">
<ItemsControl.ItemTemplate>
<DataTemplate>
<DockPanel>
<ComboBox DockPanel.Dock="Left"/>
<ComboBox DockPanel.Dock="Left"/>
<Button DockPanel.Dock="Right">Button</Button>
<!-- This will appear before the button...it has to go after it in the XAML so it will fill properly in the DockPanel -->
<TextBox DockPanel.Dock="Left" MinWidth="100" HorizontalAlignment="Stretch"/>
</DockPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
I want the textbox to fill all the remaining space between the comboboxes and the button. I had to put the textbox last in the XAML because DockPanel will only fill the last child. It looks great; however, the tab order is now screwed up. It now tabs combobox-combobox-button-textbox instead of combobox-combobox-textbox-button.
I tried using KeyboardNavigation.TabIndex
properties on each item, but since this is a DataTemplate for an ItemsControl (each of these dockpanels will be for a separate item), that made the tab order jump vertically down each of the items' comboboxes, then vertically down each textbox, then vertically down each button, rather than the desired behavior of going across each row, then down.
Example UI:
[Combo11] [Combo12] [Text1] [Button1]
[Combo21] [Combo22] [Text2] [Button2]
In the current state of affairs, it goes Combo11,Combo12,Button1,Text1,Combo21,Combo22,Button2,Text2
. If I add TabOrder properties, it goes Combo11,Combo21,Combo12,Combo22,Text1,Text2,Button1,Button2
.
I'd like it to go Combo11,Combo12,Text1,Button1,Combo21,Combo22,Text2,Button2
.
Does anyone have any ideas on how to solve this UI problem?