Instead of attaching a PreviewKeyUp
event with each TextBox
in my app and checking if the pressed key was an Enter key and then do an action, I decided
When the user presses the Enter key in the TextBox, the input in the text box appears in another area of the user interface (UI).
The following XAML creates the user interface, which consists of a StackPanel, a TextBlock, and a TextBox.
Type some text into the TextBox and press the Enter key.
The following code behind creates the KeyDown event handler. If the key that is pressed is the Enter key, a message is displayed in the TextBlock.
private void OnKeyDownHandler(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return)
{
textBlock1.Text = "You Entered: " + textBox1.Text;
}
}
For more info read MSDN Doc