Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF KeyDown and Keyup events [duplicate]

Hi when I do in one of my user controls in a WPF application,

this.KeyUp += new KeyEventHandler(ControlViewer_KeyUp);

or

this.KeyDown += new KeyEventHandler(ControlViewer_KeyUp);

or

this.AddHandler(Window.KeyDownEvent, new KeyEventHandler(ControlViewer_KeyUp), true);

I can never get the key events to fire when pusing a key on the keyboard.

Would anyone know why?

like image 886
TheWommies Avatar asked Dec 09 '09 03:12

TheWommies


1 Answers

the event is probably being handled before you can get to it, if any handlers mark the KeyEventArgs e.Handled = true; you wont get the notification, try using the PreviewKeyDown or PreviewKeyUp events and see if you have more luck.

like image 167
Aran Mulholland Avatar answered Oct 15 '22 03:10

Aran Mulholland