WPF DataGrid:如何禁用对特定DataGridRow的选择/聚焦?

WPF DataGrid:如何禁用对特定DataGridRow的选择/聚焦?,wpf,datagrid,focus,selection,Wpf,Datagrid,Focus,Selection,我希望当用户按下向下/向上键时,键盘焦点跳过特定的行并跳出它们。 我已经尝试过设置Focusable=false(在每个子代上),在这种情况下,焦点不在那一行,但也不会超出那一行。如果您使用的是MVVM,您可以使用DataGrid InputBindings来处理上下箭头键,并根据需要设置SelectedDataGridItem- <DataGrid ItemsSource="{Binding DataGridItems}" SelectionMode=

我希望当用户按下向下/向上键时,键盘焦点跳过特定的行并跳出它们。
我已经尝试过设置
Focusable=false
(在每个子代上),在这种情况下,焦点不在那一行,但也不会超出那一行。

如果您使用的是MVVM,您可以使用DataGrid InputBindings来处理上下箭头键,并根据需要设置SelectedDataGridItem-

    <DataGrid ItemsSource="{Binding DataGridItems}"
              SelectionMode="Single"
              SelectionUnit="FullRow"
              SelectedItem="{Binding SelectedDataGridItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
        <DataGrid.InputBindings>
            <KeyBinding Command="{Binding Path=ChangeSelectedItemCommand}" 
                        CommandParameter="ArrowDown"
                        Key="Down"/>
            <KeyBinding Command="{Binding Path=ChangeSelectedItemCommand}"
                        CommandParameter="ArrowUp"
                        Key="Up"/>
        </DataGrid.InputBindings>
    </DataGrid>