Click here to Skip to main content
15,847,653 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have a XAML form in MVVM, and there are some textbox and button controls, and I set the TabIndex property for that control, but when I click on tab button from keyboard, it's going to control according to tabindex set.

Please help how to set the focus from one control to another using MVVM pattern.

What I have tried:

        <Grid Grid.Column="2" Grid.Row="0"  Name="grv">

            <TextBox TabIndex="0" Grid.Column="1" Grid.Row="0" Name="txtSearchAudit" Text="{Binding SearchJob,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource textbox-editable}" IsEnabled="{Binding IsBarcodeNumberEnabled}">

            <Button TabIndex="3" Name="Search" Grid.Column="1" 
            Grid.Row="0" Width="100" Height="25" Content="Search" 
            HorizontalAlignment="Right" Style="{StaticResource btn-primary}" 
            Visibility="{Binding SearchButtonVisibility}">
        <TextBlock Grid.Column="4" Grid.Row="0" Text="Job# : 
        " Style="{StaticResource textblock}" />
        <TextBox TabIndex="4" Grid.Column="5" Grid.Row="0"  
        Style="{StaticResource textbox-readonly}" 
        Text="{Binding JobInfo.JobNumber}"  />

        <TextBlock Grid.Column="1" Grid.Row="2" 
        Text="Customer Name : " Style="{StaticResource textblock}" />
        <TextBox TabIndex="2" Grid.Column="2" Grid.Row="2"  
        Style="{StaticResource textbox-readonly}" 
        Text="{Binding JobInfo.CustomerName}"  />

        <TextBlock Grid.Column="4" Grid.Row="5" 
        Text="Scan Type : " Style="{StaticResource textblock}" />
        <TextBox TabIndex="1" Grid.Column="5" Grid.Row="5"  
        Style="{StaticResource textbox-readonly}" 
        Text="{Binding JobInfo.ScanType}"  />
Updated 19-Oct-23 8:46am

1 solution

MVVM has nothing to do with the Tab order of controls.

TabIndex sets the tab order when the Tab key is pressed. If you want a different Tabbing order, then change the TabIndex to the order that you want.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900