C# - 如何覆盖文本框的"向上箭头"和"向下箭头"的操作?

Kit*_*tze 5 c# wpf

我有一个文本框,在它下面我有一个列表框.

当用户按下向上或向下箭头时键入文本框,他应该在列表框中进行选择.文本框检测所有字符(空格除外),但似乎无法检测箭头按下.

对此有何解决方案?这是一个WPF项目顺便说一句.

编辑,感谢T.Kiley,这是工作代码:

    private void searchBox_PreviewKeyDown(object sender, KeyEventArgs e)
    {
        if (e.IsDown && e.Key == Key.Down)
        {
            e.Handled = true;
            //do your action here

        }
        if (e.IsDown && e.Key == Key.Up)
        {
            e.Handled = true;
            //do another action here
        }
    }
Run Code Online (Sandbox Code Playgroud)

Ant*_*ell 3

我刚刚尝试过这个并且有效。将预览按键按下事件添加到文本框

   private void TextBox_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
    {
        if (e.IsDown && e.Key == Key.Down)
            MessageBox.Show("It works");
    }
Run Code Online (Sandbox Code Playgroud)