5

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?

Martin Liversage
  • 104,481
  • 22
  • 209
  • 256
TheWommies
  • 4,922
  • 11
  • 61
  • 79
  • try this answer http://stackoverflow.com/questions/347724/how-can-i-capture-keydown-event-on-a-wpf-page-or-usercontrol-object – MrTelly Dec 09 '09 at 03:37

1 Answers1

6

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.

Martin Liversage
  • 104,481
  • 22
  • 209
  • 256
Aran Mulholland
  • 23,555
  • 29
  • 141
  • 228