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.
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)?