【发布时间】:2019-09-19 13:32:44
【问题描述】:
我希望当用户按下/向上时,键盘焦点会跳过特定的行并跳过它们。
我试过只设置Focusable = false(在每个后代上),在这种情况下,焦点不会进入该行,但也不会超出它们。
【问题讨论】:
标签: wpf datagrid focus selection
我希望当用户按下/向上时,键盘焦点会跳过特定的行并跳过它们。
我试过只设置Focusable = false(在每个后代上),在这种情况下,焦点不会进入该行,但也不会超出它们。
【问题讨论】:
标签: wpf datagrid focus selection
如果您使用的是 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>
【讨论】: