WPF: How to prevent a control from stealing a key gesture?

后端 未结 3 1853
有刺的猬
有刺的猬 2021-01-04 04:50

In my WPF application I would like to attach an input gesture to a command so that the input gesture is globally available in the main window, no matter which control has th

3条回答
  •  一个人的身影
    2021-01-04 05:13

    Using PreviewKeyDown is exactly what you should do... the "PreviewXYZ" events are fired from the bottom up (so the Window gets it first, then the control)... that lets you do whatever you wanted to do globaly on the "Window" level.

    Then, you can choose to say "IsHandled = true" which would prevent it from going to the next control (as far as you are concerned), but you don't have to do this. If you want the event to bubble, then just add your code and leave "IsHandled" to false.

提交回复
热议问题