this is my first question, so sorry if I've not done something correctly.
I can find nothing on the internet regarding this topic:
When I create a new wpf app with the following Grid, tab order is as expected (first textbox, down):
<Grid>
<TextBox x:Name="textBox" HorizontalAlignment="Left" Height="23" Margin="95,95,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120" />
<TextBox x:Name="textBox1" HorizontalAlignment="Left" Height="23" Margin="95,160,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
<TextBox x:Name="textBox2" HorizontalAlignment="Left" Height="23" Margin="95,217,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
</Grid>
If I set Panel.ZIndex on one of them, it can affect the tab index in different ways (depending on which one). This one is the most notable, since it seems to reverse the tab order:
<Grid>
<TextBox x:Name="textBox" HorizontalAlignment="Left" Height="23" Margin="95,95,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120" />
<TextBox x:Name="textBox1" HorizontalAlignment="Left" Height="23" Margin="95,160,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120" Panel.ZIndex="2"/>
<TextBox x:Name="textBox2" HorizontalAlignment="Left" Height="23" Margin="95,217,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
</Grid>
So how does this work? Does zindex really affect the tab order, or does it somehow create a new tab group to hold the controls with the same zindex? Is there a way to stop this so zindex has no impact at all?
I would prefer a solution that doesn't involve hard coding the tab order using the TabIndex property. Ideally there would be some way to prevent the zindex interfering
If you do not set the _TabIndex_es, ZIndex matters. This is because KeyboardNavigation uses VisualTreeHelper.GetChild() to find the next child (See GetNextSibling(...) in KeyboardNavigation source code) and this method returns visuals with lower _ZIndex_es first. If you hard code the TabIndex everything is as expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With