C# 通过键盘输入在按钮点击时触发

C# 通过键盘输入在按钮点击时触发,c#,wpf,C#,Wpf,我目前正在用C#wpf写文章,我想模仿用户按键时点击按钮的动作 private void abuttonispressed(object sender, System.Windows.Input.KeyEventArgs e) { if ((Keyboard.Modifiers == ModifierKeys.Control) && (e.Key == Key.S))

我目前正在用C#wpf写文章,我想模仿用户按键时点击按钮的动作

private void abuttonispressed(object sender, System.Windows.Input.KeyEventArgs e)
                {
                    if ((Keyboard.Modifiers == ModifierKeys.Control) && (e.Key == Key.S)) 
                    {
                        //click event is raised here
                    } 


                }
重要的是,不仅要运行该按钮的代码,而且要可视化地“点击”按钮。我读过这篇文章,并提出了一些建议,比如performclick,但performclick并不是按钮的已知方法


有什么想法吗?

我不知道正确的答案,但我会从这里开始玩:

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));
    } 
}

我不明白为什么当你按下一个组合键时,按钮会明显地被按下,更不用说“重要”了。我见过的其他用户界面都没有这样的功能。如果你只是为了与众不同、新颖或有创意而这样做,这应该会敲响警钟,你应该重新考虑。这不是与众不同或有创意的问题,我只是希望用户能够用键盘控制应用程序并获得视觉反馈,以便他们知道自己激活了什么。。有许多用户界面都在这样做,最明显的例子是在选定的按钮上按enter键以激活其单击功能。