删除或修改标准命令的默认按键手势

发布于 2024-09-15 09:47:18 字数 723 浏览 3 评论 0原文

我需要删除(或至少更改)与 wpf 标准命令关联的默认手势。

这是我的问题:

我有一个数据网格(来自 infragistics 的 XamDataGrid),我已将其关联到我创建的自定义命令。该命令使用“ctrl-delete”手势。
只要我不编辑单元格的值,这种方法就有效。

当我编辑单元格时,会使用文本编辑器。当我使用“ctrl-delete”手势时,不会执行我的命令,而是执行DeleteNextWord 命令。
这是正常的,文本编辑器具有焦点,并且由于没有附加绑定或输入手势,因此使用类。

这就是我的问题所在。我无法(不过分)向 TextEditor 的该实例添加绑定或输入手势。

因此,我尝试使用的方法是删除或修改“DeleteNextWord”命令的“默认”按键手势。

在使用 .Net Reflector 查看并了解命令的注册方式后,我发现框架从资源中获取与命令关联的密钥。

就我而言,手势“ctrl-delete”来自资源“ExceptionStringTable”(内部类型 SR,静态构造函数)中的键“KeyDeleteNextWord”。

所以我的问题是:

我可以覆盖资源“ExceptionStringTable”中“KeyDeleteNextWord”的值吗?

或者,以更一般的方式:

如何全局修改标准 WPF 命令的默认手势?

如果需要,我很乐意提供更多信息。

谢谢。

I need to remove (or at least change) the default gestures associated with the wpf standard commands.

Here's my problem :

I have a Datagrid (XamDataGrid from infragistics) to which i have associated a custom command I've created. That command uses the "ctrl-delete" gesture.
That works as long as I'm not editing the value of a cell.

When I'm editing a Cell, a TextEditor is used. When I use the "ctrl-delete" gesture, instead of executing my command, the DeleteNextWord command is executed.
That's normal, the TextEditor has focus, and as there are no bindings or inputgestures attached, the class ones are used.

That's where lies my problem. I cannot (without being overkill) add a binding or input gesture to that instance of TextEditor.

So the method I'm trying to use is to either remove or modify the "default" key gesture of the DeleteNextWord command.

After looking around with .Net Reflector to understand how the commands were registered, I saw that the framework gets the key associated to the command from a resource.

In my case, the gesture "ctrl-delete" comes from the key "KeyDeleteNextWord" in the resource "ExceptionStringTable" (internal type SR, static constructor).

So my question :

Hoe can I overwrite the value of "KeyDeleteNextWord" in the resource "ExceptionStringTable" ?

or, in a more general way :

How can I globally modify the default gesture of a standard WPF command ?

I would gladly provide more information if needed.

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只为守护你 2024-09-22 09:47:18

我没有 XamDataGrid,但我尝试使用常规 TextBox。

tb.PreviewKeyDown += new KeyEventHandler(tb_KeyDown);
void tb_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.X && Keyboard.Modifiers == ModifierKeys.Control)
        {
            Trace.WriteLine("Ctrl+X");
            e.Handled = true;
        }
    }

该代码将绕过默认的“剪切”命令。

在您的项目中,您可能需要修改控件模板,然后使用 TextEditor 上的附加属性或行为来拦截击键并调度您自己的命令。

I don't have XamDataGrid but I tried with regular TextBox.

tb.PreviewKeyDown += new KeyEventHandler(tb_KeyDown);
void tb_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.X && Keyboard.Modifiers == ModifierKeys.Control)
        {
            Trace.WriteLine("Ctrl+X");
            e.Handled = true;
        }
    }

That code will bypass the default "Cut" command.

In your project you may need to modify the control template then use attached property or behavior on TextEditor to intercept the keystroke and dispatch your own command.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文