Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello,
i bound a InputGesture to a Command, which partly works.
looks as Follows:

Code Behind:

C#
public static RoutedCommand myCommand = new RoutedCommand();
private void MyCommandExecuted(object sender, ExecutedEventArgs e)
{
    MessageBox.Show("Test");
}


XML
<UserControl.CommandBindings>
<CommandBinding Command="var:UserControlName.myCommand" Executed="MyCommandExecuted">
</Usercontrol.CommandBindings>

<USerControl.InputBindings>
<KeyBinding Command="var:UserControlName.myCommand" Key="A">
</USerControl.InputBindings>


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
Posted
Updated 31-May-12 4:08am
v2

1 solution

try

XML
<UserControl Focusable="True">
 
Share this answer
 
v2
Comments
Motil88 1-Jun-12 1:34am    
that doesn`t bring any effekt, it is still the same as before, can i set the focus in code? maybe that helps?

greets
Motil88 1-Jun-12 1:54am    
The Tipp with Focus was correct, set the focus manuallly with UserControl.Focus(), and magic, it works as i want

thanks
greets MOTI

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900