简体   繁体   中英

Grid default tab order

With the Grid control, it appears that the default tab order is by row, then by column. That is, I can tab through all the controls in the first column, then all the controls in the second column.

However, I'd like to be able to tab through all the controls in the first row, then all the controls in the second row.

I've solved this problem by setting the TabIndex for each control. But it would be nice if I didn't have to code this manually. Is there a way to change the default tab order?

The default tab order is not by row then by column.

You can easily check this with the below XAML:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition />
        <ColumnDefinition />
    </Grid.ColumnDefinitions>

    <TextBox Grid.Row="0" Grid.Column="0" />
    <TextBox Grid.Row="0" Grid.Column="1" />
    <TextBox Grid.Row="1" Grid.Column="0" />
    <TextBox Grid.Row="1" Grid.Column="1" />
</Grid>

This will go through the textboxes row-by-row, left to right starting from the top left textbox.

If you change the order to this:

<TextBox Grid.Row="0" Grid.Column="0" />
<TextBox Grid.Row="1" Grid.Column="0" />
<TextBox Grid.Row="1" Grid.Column="1" />
<TextBox Grid.Row="0" Grid.Column="1" />

It will tab through the controls in counter clockwise manner starting from top left.

So the default order is determined by order they are in the visual tree. You can try and change your XAML to reflect the tab order you'd like.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM