I have a view in WPF that I have been fighting to get the tab order correct on. I have three text boxes (lets call them Text1, Text2, and Text3) and two custom controls, eac
I don't have your custom control to hand, so I created one that contained just a TextBox. After wiring this up to your XAML, I found that the tab order went as follows:
TextBox1, TextBox2, CustomControl1, CustomControl2, TextBox3, TextBox within CustomControl1, TextBox within CustomControl2.
Note that after TextBox2 tabbing moves the focus onto the custom controls themselves, not any child controls they happen to have. The TextBox in my custom control didn't have a TabIndex, so its TabIndex was assumed to be the default value, Int32.MaxValue (see the MSDN documentation for the TabIndex property). Hence they come last in the tab order.
I found that things worked better if I marked the custom controls as IsTabStop="False"
(I don't see why I'd want the focus on the custom controls themselves), and set the tab-index of the TextBox in the custom control to that given in the <my:CustomControl />
element by adding the attribute TabIndex="{TemplateBinding TabIndex}"
to the TextBox in the custom control. Once I'd done that, the tab order was, as I would expect,
TextBox1, TextBox2, TextBox within CustomControl1, TextBox within CustomControl2, TextBox3.
Of course, my custom control consists only of a single TextBox, so setting a single tab-index fixed things for me. I don't have your code, so I can't say for sure, but it might be enough to set the tab-index of all child controls within your custom controls to that in the <my:CustomControl />
element in the same way.
EDIT: if you can't use a TemplateBinding
, and instead have a .xaml file with a corresponding .xaml.cs file, then you have what's called a user control, not a custom control. In that case,
you can try setting the tab index inside the XAML for CustomControlA using something like the following:
TabIndex="{Binding Path=TabIndex, RelativeSource={RelativeSource AncestorType={x:Type my:CustomControlA}}}"
Please post your XAML code. In the meantime, some things to consider include: