1

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?

Emond
  • 50,210
  • 11
  • 84
  • 115
Mike Eason
  • 9,525
  • 2
  • 38
  • 63

1 Answers1

0

I don't believe this is possible because the control would need to have two different data context and as far as I know it isn't possible to do.

EDIT: Actually upon further reading, you may be able to do something like this: Multiple dataContext for one control - MVVM

Community
  • 1
  • 1
ProgrammingDude
  • 597
  • 1
  • 5
  • 25