3

I am trying to make F4 open another window, but I have some of my windows set so when they are opened, the insertion is set to a default TextBox or ComboBox, so since the focus is on that it does not recognize that I pressed f4, but for some reason it does recognize other F keys. It also does not recognize the insert key.

I am wondering how I could fix this

private void wCarrierContractSurcharge_KeyDown(object sender, KeyEventArgs e)
{
    CommonCode.ApplyStandardKeyShortcuts(this, e);
}
Draken
  • 3,134
  • 13
  • 34
  • 54
ricks
  • 3,154
  • 31
  • 51

1 Answers1

4

KeyDown is a bubbling event, which means it is fired in the current UIElement first and "bubbles up" to the parent elements if it is not handled. In this case, many UI elements handle F4 to open dropdowns or do various other tasks. Since the ComboBox and TextBox are handling the event themselves, it doesn't get bubbled up to the window, so the window's KeyDown handler will not fire.

If you want the window to override its child elements, you should use PreviewKeyDown instead. This is a tunneling event, meaning the handler of the parent control is fired first and tunnels down to the child control if it isn't handled.

See this answer for more information on tunneling and bubbling events.

Community
  • 1
  • 1
Tim Copenhaver
  • 3,282
  • 13
  • 18
  • @RickS mark it as answer (the checkmark icon below where you vote) and give the dude his credit as well as letting other readers know it's sorted. :) – Chris W. Jun 13 '16 at 18:39