C#如何禁用键绑定 [英] C# how to disable keybinding

查看:79
本文介绍了C#如何禁用键绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MenuItem 控件具有便捷的属性IsEnabled(继承自 UIElement ).这样,我可以在适当的情况下隐藏该菜单选项显示的命令.

The MenuItem control has the convenient property IsEnabled (inherited from UIElement). This allows me to, when appropriate, hide the command exposed by that menu option.

但是,如果该命令也绑定到某个键(例如Ctrl + K),则用户仍然可以访问它.如何将IsEnabled功能获取到 KeyBinding ?

But if that command is also bound to a key (e.g. Ctrl+K), the user can still access it. How do I get the IsEnabled functionality to a KeyBinding?

推荐答案

如果将KeyBinding绑定到ICommand,则只需设置

If you bind the KeyBinding to an ICommand, you can just set the ICommand.CanExecute to false (and potentially raise CanExecuteChanged).

这将禁用" KeyBinding,因为命令本身将被禁用.

This will "disable" the KeyBinding since the command itself will be disabled.

这篇关于C#如何禁用键绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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