无法在 wpf 的组合框中捕获向下箭头 [英] could not capture down arrow in combobox in wpf

查看:21
本文介绍了无法在 wpf 的组合框中捕获向下箭头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 wpf 的窗口上有一个组合框,我试图捕捉这个组合框的向下箭头键,但我无法这样做.以下是我对组合框的唯一代码.

I have a combobox on a window in wpf and i am trying to capture the down arrow key of this combobox but i am not able to do so. The following is the only code i have for the combobox.

<ComboBox Height="23" HorizontalAlignment="Left" Margin="10,10,0,0" Name="comboBox1" VerticalAlignment="Top" Width="120"
              PreviewKeyDown="comboBox1_PreviewKeyDown" KeyDown="comboBox1_KeyDown" IsEditable="True"/>

C#

private void comboBox1_PreviewKeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Down)
            MessageBox.Show("hi");
    }

    private void comboBox1_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Down)
            MessageBox.Show("hi");
    }

当我按下箭头键时,事件甚至没有被击中.

The event is not even hit when i press down arrow key.

推荐答案

尝试处理 PreviewKeyUp(或 KeyUp).如果这不起作用,那么您的窗口或代码中必须有更多内容(您是否正在处理这些事件的其他实例)?

Try handling PreviewKeyUp (or KeyUp) instead. If that does not work, then there must be more to your window or code (are you handling other instances of these events)?

这篇关于无法在 wpf 的组合框中捕获向下箭头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆