How do I stop WPF KeyDown events from bubbling up from certain contained controls (such as TextBox)?

前端 未结 2 920
庸人自扰
庸人自扰 2021-02-20 12:57

My program is quite large, and uses WPF, and I want to have a global shortcut key that uses \'R\', with no modifiers.
There are many controls such as TextBox, ListBox, Combo

2条回答
  •  走了就别回头了
    2021-02-20 13:38

    There is an event when you handle KeyDown event and it should pass you a KeyEventArgs. From there you can set the Handled to true so that it won't bubble up.

    Sample

    private void TextBoxEx_KeyAction(object sender, KeyEventArgs e)
    {
      e.Handled = true;
    }
    

提交回复
热议问题