【解決方法】MVVMでタブボタンを押して次のコントロールに移動する方法


MVVMにxamlフォームがあり、いくつかのテキストボックスとボタンコントロールがあり、そのコントロールにTabIndexプロパティを設定しましたが、キーボードからタブボタンをクリックすると、設定されたtabindexに従って制御されます。

MVVMパターンを使用して、あるコントロールから別のコントロールにフォーカスを設定する方法を教えてください。

私が試したこと:

        <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}">
                
            </TextBox>


            <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}">
               
            </Button>
        </Grid>
        <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}"  />
</Grid>

解決策 1

MVVM コントロールのタブ順序とは関係ありません。

TabIndex Tab キーを押したときのタブ オーダーを設定します。 別のタブ順序を変更したい場合は、 TabIndex ご希望の順番に。

コメント

タイトルとURLをコピーしました