I'm currently writing in C# wpf and开发者_如何转开发 I would like to imitate the action of clicking a button by the user pressing a key.
private void abuttonispressed(object sender, System.Windows.Input.KeyEventArgs e)
{
if ((Keyboard.Modifiers == ModifierKeys.Control) && (e.Key == Key.S))
{
//click event is raised here
}
}
It's vital that not only the code of that button is run but also the visual 'clicking' of the button. I read about this and suggestions like performclick were made but performclick is not a known method for the button somehow...
Any ideas?
I don't know the right answer, but would start playing from here:
private void abuttonispressed(object sender, System.Windows.Input.KeyEventArgs e)
{
if ((Keyboard.Modifiers == ModifierKeys.Control) && (e.Key == Key.S))
{
//click event is raised here
button1.Focus();
button1.RaiseEvent(new RoutedEventArgs(Button.ClickEvent, button1));
}
}
精彩评论