TextInput Bubbling Occurs when a keystroke is complete and
the element is receiving the text input.
This event isn??™t fired for keystrokes that
don??™t result in text.
PreviewKeyUp Tunneling Occurs when a key is released.
KeyUp Bubbling Occurs when a key is released.
Keyboard handling is never quite as straightforward as it seems. Some controls may
suppress some of these events so they can perform their own more specialized keyboard handling.
The most notorious example is the TextBox control, which suppresses the TextInput
event. The TextBox also suppresses the KeyDown event for some keystrokes, such as the arrow
keys. In cases like these, you can usually still use the tunneling events (PreviewTextInput and
PreviewKeyDown).
The TextBox control also adds one new event, named TextChanged. This event fires
immediately after a keystroke causes the text in the text box to change. At this point, the new
text is already visible in the text box, so it??™s too late to prevent a keystroke you don??™t want.
Handling a Key Press
The best way to understand the key events is to use a sample program such as the one shown
in Figure 6-6. It monitors a text box for all the possible key events and reports when they
occur. Figure 6-6 shows the result of typing a capital S in a text box.
CHAPTER 6 n DEPENDENCY PROPERTIES AND ROUTED EVENTS 170
Figure 6-6.
Pages:
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337