您的位置:首页 > 其它

WPF让button响应按键

2015-06-24 19:36 281 查看
在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,加入想要实现的功能

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: