I'm trying to bind any keyboard key pressed to a command in the ViewModel
.
I know that I can bind a specific key, using:
<Window.InputBindings>
<KeyBinding Command="{Binding ChangeIdCommand}" Key="B"/>
</Window.InputBindings>
Can I bind all key presses to ChangeIdCommand
without having to type them all manually?
Try this after your window definition:
<Window x:Class="wpfApplication.MainWindow"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" ...>
<i:Interaction.Triggers>
<i:EventTrigger EventName="KeyDown">
<i:InvokeCommandAction Command="{Binding ChangeIdCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With