我的快捷键不起作用 [英] My key shortcut isn't working

查看:76
本文介绍了我的快捷键不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向菜单项添加快捷方式,但是无法正常工作.

I am tryiong to add a shortcut to my menu Item but It doesn't seams to work.

这是我的菜单项:

<MenuItem Name="openMenuItem" Header="Open file" InputGestureText="Ctrl+O" Command="{Binding OpenFile}"></MenuItem>

我在这里做什么错了?

这是我的菜单图片:

推荐答案

针对您特别提出的问题:

In response to the question you specifically asked:

我在这里做什么错了?

What am I doing wrong here?

我将您定向到文档, InputGestureText属性:

I direct you to the documentation for the InputGestureText property:

此属性不将输入手势与菜单项关联;只是将文本添加到菜单项.

This property does not associate the input gesture with the menu item; it simply adds text to the menu item.

其行为符合设计要求. InputGestureText只是在菜单项上显示一些文本;它不会改变行为,尤其是它实际上不会监听该键手势.鉴于WinForms中的相应属性确实具有添加行为,这在某种程度上是出乎意料的,但是属性名称的后缀Text也将其调出,这不是输入手势,而只是文本显示给告诉用户有关输入手势的信息.使用RoutedUICommand时会自动设置它,但是当您自己实现ICommand时,要由您设置InputGestureText并监听按键手势.

It's behaving as designed. InputGestureText just displays some text on the menu item; it does not change behavior, and in particular, it does not actually listen for that key gesture. This is somewhat unexpected, given that the corresponding property in WinForms does add behavior, but it's also called out by the Text suffix on the property name -- it's not the input gesture, it's just the text that's displayed to tell the user about the input gesture. It's set automatically when you use RoutedUICommand, but when you implement ICommand yourself, it's up to you to both set InputGestureText and listen for the key gesture.

您正在做的错误是期望此属性直观地表现.您远不是唯一一个对此感到困惑的人.

What you're doing wrong is expecting this property to behave intuitively. You're far from the only one to be confused by this.

(显而易见的后续问题是如何为我的MVVM命令添加键盘快捷方式",但这是一个单独的问题-在StackOverflow上已被多次询问和回答;一旦您知道那是正确的要提出的问题,您应该可以搜索现有的答案.)

(The obvious follow-on question is "how do I add a keyboard shortcut for my MVVM command", but that's a separate question -- and one that's been asked and answered on StackOverflow multiple times; once you know that's the right question to be asking, you should be able to search for existing answers.)

这篇关于我的快捷键不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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