使用Key.App打开时,上下文菜单消失 [英] Context menu disappears when opened with Key.App

查看:77
本文介绍了使用Key.App打开时,上下文菜单消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#/WPF中的上下文菜单有一个小问题.我将在附加到矩形的画布中打开它.我定义了使用空格键打开它,并且效果很好.现在,我想更改为应用程序键(又名菜单键,应用程序键,Contxt键等).当我按下App-Key时,会出现上下文菜单,但是只要松开该键,它就会消失.对于测试用例,我也使用键"a"进行了尝试,它也可以正常工作.有人知道释放按钮后为什么消失了吗?此键有一些特殊的行为吗?

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?

这是代码:

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;
  }
}

推荐答案

对于所有有相同问题的人,以下是解决方法: App-key不应在KeyDown事件中处理,而必须在KeyUp事件中处理.

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, 奥西

这篇关于使用Key.App打开时,上下文菜单消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆