Keydown event: how to capture and enlarge key lines?

I try to grab the down and up keys (direction lines), but when I press these keys, it does not trigger events.

However, if I press any other key, the event is raised. For example, numlock is caught. Are the row keys special keys?

I use MVVMLight to convert events to a command and pass KeyEventArgs.

Thanks.

EDIT: add code

Well. indeed, I have comboBox and is editable, so I can write text inside comboBox. As a search option is enabled, when I write, the selection is changed.

Thus, the choice can change for many reasons: I write, and comboBox changes the choice due to the search option, I can change the selection with the mouse, and I can change the selection with the arrow keys.

I would like to know what is the reason for the change of choice. So I need to know when in my comboBox I press the up or down arrow keys.

I have this code:

Axml

<ComboBox DisplayMemberPath="Type" Height="23" HorizontalAlignment="Left" IsSynchronizedWithCurrentItem="True" Margin="0,16,0,0" Name="cmbType" VerticalAlignment="Top" Width="238" ItemsSource="{Binding Path=Types}" SelectedIndex="{Binding Path=TypesIndex}" IsEditable="True" Text="{Binding TypesText}"> <i:Interaction.Triggers> <i:EventTrigger EventName="PreviewKeyDown"> <cmd:EventToCommand Command="{Binding TypesPreviewKeyDownCommand, Mode=OneWay}" PassEventArgsToCommand="True" /> </i:EventTrigger> <i:EventTrigger EventName="SelectionChanged"> <cmd:EventToCommand Command="{Binding TypesSelectionChangedCommand, Mode=OneWay}" CommandParameter="{Binding ElementName=cmbTypes, Path=SelectedItems}" /> </i:EventTrigger> </i:Interaction.Triggers> </ComboBox> 

In my view, Model:

 private RelayCommand<KeyEventArgs> _typesPreviewKeyDownCommand = null; public RelayCommand<KeyEventArgs> typesPreviewKeyDownCommand { get { if (_typesPreviewKeyDownCommand == null) { _typesPreviewKeyDownCommand = new RelayCommand<KeyEventArgs>(typesPreviewKeyDownCommand); } return _typesPreviewKeyDownCommand; } } private void typesPreviewKeyDownCommand(KeyEventArgs e) { if (e.Key == Key.Down || e.Key == Key.Up) { //my code } else { //more code } } 
+4
events wpf mvvm-light
source share
1 answer

Not sure if more appropriate, but here's an article on CodeProject that discusses a very similar issue / behavior Up / down behavior on DatePicker

This is very easy to handle in Code Behind, as in the article, but if you want to do it in MVVM style, you need to go with i:Interaction or InputBindings . I prefer Interaction, since in combination with mvvm-light it works better for me, and with InputBindings I found that the up / down keys do not work, and the ALT modifier will work.

As the comments say, it is probably processed somewhere along the way before it gets to you. (this is why you would like to use PreviewKeyDown , not KeyDown ).

+3
source share

All Articles