1

I have textbox catching KeyDown events like this:

 <Style TargetType="TextBox">
        <EventSetter Event="KeyDown" Handler="TextBoxInput"/>
    </Style>

It works for all key and key combinations except spacebar. Even space with modifiers works ok, only space alone does not come to my method.

Is there anything I can change on the textbox to fire the event also on spacebar alone?

Tomas Grosup
  • 6,396
  • 3
  • 30
  • 44
  • 1
    possible duplicate of [WPF: OnKeyDown() not being called for space key in control derived from WPF TextBox](http://stackoverflow.com/questions/1458748/wpf-onkeydown-not-being-called-for-space-key-in-control-derived-from-wpf-text) – Habib Sep 11 '12 at 11:14

1 Answers1

4

Use the PreviewKeyDown event instead of KeyDown.

<EventSetter Event="PreviewKeyDown" Handler="TextBoxInput"/>

And you can use this article as backing for that.

Mike Perrenoud
  • 66,820
  • 29
  • 157
  • 232