Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Context menu disappears when opened with Key.App

I have a small problem with the context menu in C#/WPF. I will open it within a canvas, being attached to a rectangle. I have defined to open it with the space key, and it works fine. Now I want to change to the App-Key (aka Menu-Key, Application-Key, Contxt-Key, etc.). When I press the App-Key, the context menu appears, but as far as a release the key, it disappears. For test case, I also tried it with the key 'a', and it also works fine. Does anyone know why it disappears after releasing the button? Has this key some special behaviour?

Here is the code:

private void Rect_KeyDown(object sender, KeyEventArgs e) {
  if (e.Key == Key.Space || e.Key == Key.A || e.Key == Key.Apps) { 
     e.Handled = true;    
     componentWithFocus.MainRectangle.ContextMenu.IsOpen = true;
  }
}
like image 603
Ossi Avatar asked Nov 07 '25 15:11

Ossi


1 Answers

For all who have the same problem, here is the solution: The App-key should not be handled in the KeyDown event, is has to be handled in the KeyUp event.

BR, Ossi

like image 94
Ossi Avatar answered Nov 11 '25 15:11

Ossi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!