private void MessageTextBoxKeyDownHandler(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { SendButton.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); } }
private void InputTextBox_OnKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Return) { SendButton.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent)); // http://stackoverflow.com/questions/728432/how-to-programmatically-click-a-button-in-wpf } }
private void MessageInputBox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e) { if (e.KeyboardDevice.Modifiers == ModifierKeys.Control && e.Key == Key.Enter) { int caret = MessageInputBox.CaretIndex; MessageInputBox.Text = MessageInputBox.Text.Insert(caret, Environment.NewLine); MessageInputBox.CaretIndex = caret + Environment.NewLine.Length; return; } if (e.Key == Key.Enter) { SendButton.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); } }