Lets say I have my user-control somewhere in the visual tree. Parent and children are 3rd-party controls that I cannot modify. I want to filter keyboard events in my control so that children controls do not receive some keyboard events, but the parent controls do.
I'll try to explain what I want to achieve with some diagrams. If controls do not handle keyboard events, all events bounce through the visual tree:
But, f.e. when user presses A,
Child2.OnPreviewKeyDown()
should NOT be called- but
Parent2.OnTextInput
should still receive an event
I can achive (1) by setting e.Handled = true
in MyControl.PreviewKeyDown
. The problem is that in this case TextInput
event is not generated:
Is there a way to achieve behavior like on the 2nd picture?
Added: The problem I'm trying to solve is that a 3rd-party control (Child 2) steals some input in OnPreviewKeyDown (and marks event as handled), and I'm trying to avoid that.