I wrote a custom markup extension to "bind" InputBindings
to commands, which can be used almost like a real binding :
<UserControl.InputBindings>
<KeyBinding Modifiers="Control"
Key="E"
Command="{input:CommandBinding EditCommand}"/>
</UserControl.InputBindings>
Note that this markup extension uses private reflection, so it can only be used if your application runs in full trust...
Another option is to use the CommandReference
class. It can be found in the MVVM toolkit available here. It's probably a cleaner approach, but a bit more complex to use.
Note that in WPF 4, the InputBinding.Command
, InputBinding.CommandParameter
and InputBinding.CommandTarget
properties are dependency properties, so they can be bound normally
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…