#618 – Keyboard Event Summary

The following attached events are defined in the Keyboard class and are exposed as public events of the ContentElement, UIElement and UIElement3D classes:

  • PreviewKeyDown / KeyDown – Key is pressed  (KeyEventArgs)
  • PreviewKeyUp / KeyUp  – Key is released  (KeyEventArgs)
  • PreviewGotKeyboardFocus / GotKeyboardFocus – Element gains keyboard focus  (KeyboardFocusChangedEventArgs)
  • PreviewLostKeyboardFocus / LostKeyboardFocus – Element loses keyboard focus  (KeyboardFocusChangedEventArgs)

The following attached events are defined in the TextCompositionManager and also exposed as public events of ContentElementUIElement and UIElement3D:

  • PreviewTextInput / TextInput – Element is receiving text  (TextCompositionEventArgs)

Not strictly a keyboard or text composition event, but related, is the following attached event, which is defined in and exposed as a public event from the TextBoxBase class:

  • TextChanged – Content in text box has changed  (TextChangedEventArgs)

Tunneling events (PreviewXyz) are typically paired with a corresponding bubbling event (Xyz).  The tunneling event fires first, going down the logical tree, followed by the bubbling event, which works its way back up the logical tree.

#617 – Input Events

Elements in WPF fire various type of input events, as a user interacts with the element.  There are four basic types of input events.

  • Keyboard events – Fire when user presses keys on the keyboard
  • Mouse events – Fire when a user does something with the mouse–e.g. moves the mouse or presses a mouse button
  • Touch events – Fire when a user uses their finger to touch an element (requires touch-sensitive screen)
  • Stylus events – Fire when the user uses a stylus device to touch an element on the screen  (requires a stylus device and touch-sensitive screen)