tags:

views:

18

answers:

1

Hello everyone,

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.

A: 

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.

Kai Wang
Even if it works I don't like the idea of having to add code to block the execution of the command.Moreover, I need to have access to the textbox to add the handler to the event, and that's the problem.I cannot (easily) have access to the textbox that's embed into the cell of the grid.Isn't there a more clean way remove or modify a class binding or class gesture ?
Cerel
@Cerel, as I said, use attached property or behavior, it's the typical way to extend a control when you don't have the source code. And I don't know why you are against writing code. What else do you want to do to make this happen?
Kai Wang
In the first place I created the command to remove code from the PreviewKeyDown event ... I don't have easy access to the textboxes, so I cannot attach anything to them. If I had an easy access I would already had put an inputbinding to either my command or to "NotACommand". Isn't there a way to update an existing resource string ?
Cerel