I've come across some unusual behaviour, I'd like to use a KeyBinding
to bind the Enter
key to a command in my view model, but I also want to subscribe to the KeyUp
event on the control in the view's code-behind. Here's an example:
<TextBox Name="txtCustomBarcode"
KeyUp="CustomBarcode_KeyUp">
<TextBox.InputBindings>
<KeyBinding Command="{Binding ScanBarcodeCommand}"
CommandParameter="{Binding Text, ElementName=txtCustomBarcode}"
Key="Enter"/>
</TextBox.InputBindings>
</TextBox>
If I use this method, then only the command will get executed, the code-behind event gets ignored. If I remove the KeyBinding
, then the KeyUp
event gets called as expected.
Is there a way I can use a KeyBinding
and a KeyUp
event on the same control?