在xmal中加入,響應回車鍵,其它鍵類似
<Window.Resources>
<RoutedUICommand x:Key="ClickCommand" Text="Text" />
</Window.Resources>
<Window.CommandBindings>
<CommandBinding Command="{StaticResource ClickCommand}" Executed="EnterHandler" />
</Window.CommandBindings>
<Window.InputBindings>
<KeyBinding Key="Enter" Command="{StaticResource ClickCommand}" />
</Window.InputBindings>
在cs文件中加入函數
private void EnterHandler(object sender, RoutedEventArgs e)
{
//handle click event,加入想要實現的功能
}