1

我有这个 xaml:

<DataGrid.InputBindings>
        <KeyBinding Key="a" Command="{Binding Path=Function}" CommandParameter="{Binding ElementName=dataGrid1,Path=SelectedItem}"></KeyBinding>
        <KeyBinding Key="s" Command="{Binding Path=Function}" CommandParameter="{Binding ElementName=dataGrid1,Path=SelectedItem}"></KeyBinding>
</DataGrid.InputBindings>

当我选择一行并按 a 或 si 时,将所选项目绑定到 KeyPressed。我的问题是我怎么知道我按下了哪个键?(我想绑定按键和选定的项目)

4

1 回答 1

2

如果您有 2 个键绑定,则有 2 个不同的命令会更清楚:

<DataGrid.InputBindings>
    <KeyBinding Key="a" Command="{Binding Path=ACommand}" CommandParameter="{Binding ElementName=dataGrid1,Path=SelectedItem}"></KeyBinding>
    <KeyBinding Key="s" Command="{Binding Path=SCommand}" CommandParameter="{Binding ElementName=dataGrid1,Path=SelectedItem}"></KeyBinding>
</DataGrid.InputBindings>
于 2012-09-03T12:48:30.810 回答