开发者

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.K开发者_开发百科ey == Key.A || e.Key == Key.Apps) { 
     e.Handled = true;    
     componentWithFocus.MainRectangle.ContextMenu.IsOpen = true;
  }
}


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜