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) {
events wpf mvvm-light
รlvaro Garcรญa
source share