August 7, 2012 2 Comments
There are four basic events related to a key being pressed or released that a GUI element can fire in WPF. An event fires when you press a key down (KeyDown) and a different event fires when you release the key (KeyUp). When these events fire for an element, they fire first for the element and then work back up the logical tree, firing for each ancestor element. These are bubbling events.
There are also the PreviewKeyDown and PreviewKeyUp events, which fire before the KeyDown and KeyUp events, but fire from the top of the logical tree down to the control where the event originated. (Tunneling events).
For a Window containing a StackPanel that contains a TextBox, the event sequence when a user presses a key while the TextBox has focus is: