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?
Use the PreviewKeyDown
event instead of KeyDown
.
<EventSetter Event="PreviewKeyDown" Handler="TextBoxInput"/>
And you can use this article as backing for that.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.