【问题标题】:WPF DataGrid: how to disable selection / focus on a particular DataGridRow?WPF DataGrid:如何禁用选择/关注特定的 DataGridRow?
【发布时间】:2019-09-19 13:32:44
【问题描述】:

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

【问题讨论】:

    标签: wpf datagrid focus selection


    【解决方案1】:

    如果您使用的是 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>
    

    【讨论】:

      猜你喜欢
      • 2015-07-03
      • 1970-01-01
      • 2017-11-29
      • 1970-01-01
      • 1970-01-01
      • 2011-01-30
      • 2023-04-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多