我正在使用 WPF C# 应用程序,我需要在按下键盘上的向下箭头键时执行一些操作,例如:
private void Window_KeyDown(object sender, KeyEventArgs e)
{
// Here I gotta check is that arrow key down which invoked this event.. then call a method
DoSomething();
}
我根本不知道在 wpf 中如何检测向下箭头键.. 任何形式的帮助都会很棒!
谢谢!
最佳答案
KeyEventArgs
在 KeyEventArgs.Key
属性中保存有关按下的键的信息,因此您可以通过检查 e.Key 来检查向下箭头键
等于 Key.Down
,这是向下箭头键的枚举值。
private void Window_OnKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Down) // The Arrow-Down key
{
DoSomething();
}
}
关于c# - 如何检测何时按下向下箭头键/C# WPF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49790301/