将命令绑定到输入手势 [英] Binding a Command to an Input Gesture
问题描述
你好,
我将InputGesture绑定到命令,这部分起作用.
看起来如下:
背后的代码:
Hello,
i bound a InputGesture to a Command, which partly works.
looks as Follows:
Code Behind:
public static RoutedCommand myCommand = new RoutedCommand();
private void MyCommandExecuted(object sender, ExecutedEventArgs e)
{
MessageBox.Show("Test");
}
<UserControl.CommandBindings>
<CommandBinding Command="var:UserControlName.myCommand" Executed="MyCommandExecuted">
</Usercontrol.CommandBindings>
<USerControl.InputBindings>
<KeyBinding Command="var:UserControlName.myCommand" Key="A">
</USerControl.InputBindings>
此命令也已分配给用户控件中的按钮.如果我运行我的项目,请在键盘上按"A",则不会发生任何事情.如果我按下按钮,将显示消息框.一次按下按钮后,键盘键也起作用.如果我现在再次按"A",则也会出现messageBox.
为什么我必须先按一次Butten,然后才能使用"A"?我做错了什么?
寻求帮助
问候Moti
This command is also assigned to a button in the user Control. if i run my project, an press "A" on the Keyboard, nothing Happens. if i Press the Button, the Message Box appears. After once pressing the Button, also the Keyboard Key works. if i now press "A" again, the messageBox appears too.
Why do i i have to press the Butten once first, before i can use "A"?? What am i doing wrong?
thx for help
kind regards Moti
推荐答案
try
try
<UserControl Focusable="True">
这篇关于将命令绑定到输入手势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!