开发者

Remove or modify the default key gestures of standard commands

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 w开发者_开发知识库hich 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜