创建单个按键绑定,该按键绑定会在每次按下具有任何数字的控件时触发命令,然后将该数字作为参数传递? [英] Create a single key-binding that fires a command every time control is pressed with any number and then passes the number as a parameter?
本文介绍了创建单个按键绑定,该按键绑定会在每次按下具有任何数字的控件时触发命令,然后将该数字作为参数传递?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要为每个控件+数字组合创建热键,并且希望不创建十个命令.有什么办法吗?
I need to create hot-keys for every control + number combination and would prefer not to have create ten commands. Is there any way to do this?
推荐答案
如果我理解您的问题,那么您只有一个命令,例如MyCommand
,如果用户按下CTRL + 0到CTRL +,则要触发它9,并为每个组合指定不同的参数.
If I understand your question, you have a single command, say MyCommand
, and you want to fire it if the user presses CTRL+0 through CTRL+9, and give the command a different parameter for each combination.
在这种情况下,只需在窗口中创建10个键绑定,所有键绑定都已绑定到MyCommand
,并为它们提供一个参数:
In that case, just create 10 key bindings in your window, all bound to MyCommand
, and give them a parameter:
<Window.InputBindings>
<KeyBinding Command="MyCommand" Gesture="Ctrl+0" CommandParameter="0"/>
<KeyBinding Command="MyCommand" Gesture="Ctrl+1" CommandParameter="1"/>
<KeyBinding Command="MyCommand" Gesture="Ctrl+2" CommandParameter="2"/>
<KeyBinding Command="MyCommand" Gesture="Ctrl+3" CommandParameter="3"/>
<KeyBinding Command="MyCommand" Gesture="Ctrl+4" CommandParameter="4"/>
<KeyBinding Command="MyCommand" Gesture="Ctrl+5" CommandParameter="5"/>
<KeyBinding Command="MyCommand" Gesture="Ctrl+6" CommandParameter="6"/>
<KeyBinding Command="MyCommand" Gesture="Ctrl+7" CommandParameter="7"/>
<KeyBinding Command="MyCommand" Gesture="Ctrl+8" CommandParameter="8"/>
<KeyBinding Command="MyCommand" Gesture="Ctrl+9" CommandParameter="9"/>
</Window.InputBindings>
这篇关于创建单个按键绑定,该按键绑定会在每次按下具有任何数字的控件时触发命令,然后将该数字作为参数传递?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文