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
c # wpf xaml


source to share


No one has answered this question yet

Check out similar questions:

1327
Why is it important to override GetHashCode when the Equals method is overridden?
17
Defining InputBindings in Style
ten
Key shortcuts in WPF MVVM?
6
XAML - How to have global inputs?
five
Define InputBindings in style
3
ListBoxItem MouseBinding in ControlTemplate InputBinding not working MVVM
1
WPF MVVM C # Input Bindings with TextBox Keystrokes
1
Various modifiers to run various commands in WPF input bindings
1
The application closes automatically
0
WPF InputBinding for Hyperlink



All Articles
Loading...
X
Show
Funny
Dev
Pics