Can't override globally defined InputBindings locally with NotACommand

I am currently having problems working with WPF InputBindings. We've defined the app-level keyboard bindings, but there are some places where I want to use the default behavior for a control by setting the control's binding to NotACommand

.

This does not work (although redefining the control plane link with another command works fine). Here's some sample code:

App.xaml.cs

public void OnStartup()
{
    var window = Application.Current.MainWindow.
    window.InputBindings.Add(new KeyBinding(CommandA, Key.A, Modifiers.Control));
    window.InputBindings.Add(new KeyBinding(CommandB, Key.Delete, Modifiers.None));
}

      

SomeControl.xaml.cs

public void OverrideBindings()
{
    // this invokes LocalCommand instead of CommandA
    this.InputBindings.Add(new KeyBinding(LocalCommand, Key.A, Modifiers.Control));
    // this still invokes CommandB
    this.InputBindings.Add(new KeyBinding(ApplicationCommands.NotACommand, Key.Delete, Modifiers.None));
}

      

Any thoughts, suggestions? Or is this a completely wrong approach?

+3


source to share





All Articles