【问题标题】:KeyBindings command is not firing inside DataGrid cellKeyBindings 命令未在 DataGrid 单元格内触发
【发布时间】:2016-09-01 09:19:38
【问题描述】:

当我在 DataGrid 单元格中时,我正在尝试使用 KeyBinding 机制来触发操作。

<DataGrid.InputBindings>
    <KeyBinding Key="Esc" Command="{Binding MainWindowKeyBindings.DatabaseGridKeyBindings.EscCommand}"/>
</DataGrid.InputBindings>

这仅在我关注我的数据网格时才有效,但当我在特定单元格内时,它不会触发。我做错了什么?

【问题讨论】:

    标签: c# wpf xaml key-bindings


    【解决方案1】:
    <DataGrid.InputBindings>
    <KeyBinding Key="Esc" Command="{BindingMainWindowKeyBindings.DatabaseGridKeyBindings.EscCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}, Path=CurrentCell}"/>
    </DataGrid.InputBindings>
    

    【讨论】:

    • 感谢您的回答!
    • 你知道吗,为什么用同样的逻辑,Up/Down 箭头没有触发我的命令?我刚刚将Key="Esc" 更改为Key="Up" / Key="Down",它无法使用。
    猜你喜欢
    • 1970-01-01
    • 2016-10-22
    • 2013-08-18
    • 2016-06-14
    • 2012-03-28
    • 2012-01-15
    • 1970-01-01
    • 2018-03-02
    • 1970-01-01
    相关资源
    最近更新 更多