Tomas Grosup
Tomas Grosup

Reputation: 6514

TextBox does not fire KeyDown event on spacebar

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?

Upvotes: 1

Views: 2516

Answers (1)

Mike Perrenoud
Mike Perrenoud

Reputation: 67898

Use the PreviewKeyDown event instead of KeyDown.

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

And you can use this article as backing for that.

Upvotes: 4

Related Questions