private void OnPreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Space) { if (KeyboardHelper.AreKeyboardModifiersPressed(ModifierKeys.Control)) { UpdateSuggestionBox(true); e.Handled = true; } } if (e.Key == Key.Down) { if (_suggestionListBox.SelectedIndex < _suggestionListBox.Items.Count) { _suggestionListBox.SelectedIndex = _suggestionListBox.SelectedIndex + 1; } } if (e.Key == Key.Up) { if (_suggestionListBox.SelectedIndex > -1) { _suggestionListBox.SelectedIndex = _suggestionListBox.SelectedIndex - 1; } } if (e.Key == Key.Enter || e.Key == Key.Tab) { // Commit the selection UpdateSuggestionBox(false); e.Handled = (e.Key == Key.Enter); var binding = AssociatedObject.GetBindingExpression(TextBox.TextProperty); if (binding != null) { binding.UpdateSource(); } } if (e.Key == Key.Escape) { if (_popup.IsOpen) { // Cancel the selection UpdateSuggestionBox(false); _isUpdatingAssociatedObject = true; AssociatedObject.Text = _valueAtSuggestionBoxOpen; e.Handled = true; } } }
/// <summary> /// Called when the specified key is pressed. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.Windows.Input.KeyEventArgs"/> instance containing the event data.</param> private void OnKeyUp(object sender, KeyEventArgs e) { if (e.Key == Key) { if (CanExecuteCommand()) { ExecuteCommand(); #if NET e.Handled = true; #endif } } }
/// <summary> /// Called when the specified key is pressed. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The key event args instance containing the event data.</param> private void OnKeyDown(object sender, KeyEventArgs e) { if (!IsEnabled) { return; } if (e.Handled) { return; } if (e.Key == Key) { if (CanExecuteCommand()) { ExecuteCommand(); e.Handled = true; } } }