could not capture down arrow in combobox in wpf

后端 未结 3 1235
陌清茗
陌清茗 2021-01-25 02:36

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 com

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-25 03:04

    Create a new Combo box class by inheriting from the base ComboBox. Below code explains how to. You may come across such problems when you add combo box to another control like Data grid cell. Hope this helps!

    http://csharpquestsolution.blogspot.com/2013/11/arrow-key-events-not-getting-fired-on.html

    public class MyComboBox : ComboBox
    {
        protected override bool ProcessKeyMessage(ref Message m)
        {
            KeyEventArgs keyArgs = new KeyEventArgs((Keys)m.WParam);
            switch(keyArgs.KeyCode)
            {
                case Keys.Up :
                    //Implement your code here.
                    return true;
                case Keys.Down :
                    //Implement your code here.
                    return true;
            }
            return base.ProcessKeyMessage(ref m);
        }
    }
    

提交回复
热议问题