I noticed that when a window is handling the KeyDown event raised by a text box in it and set the event Handled flag to true, the text box ignores the pressed key and doesn’t add it to its content.
According to my understanding of how things work, the PreviewKeyDown event if first tunneling from the window to the TextBox and then the KeyDown event is bubbling up from the TextBox to the window. By the time the window’s event handler gets to set the Handled event, the event is no longer handled by the TextBox, but I do see that it has an effect, and pressed keys are not added to the TextBox.
Can someone explain how this works?
(this is a general question, but was raised after I saw a similar behavior in a third-party control we are using, and it caused me problems, as I wanted the control to handle the event but stop it from bubbling upwards.)