you can do it on KeyDown event like
<StackPanel>
<TextBlock Width="300" Height="20">
Type some text into the TextBox and press the Enter key.
</TextBlock>
<TextBox Width="300" Height="30" Name="textBox1"
KeyDown="OnKeyDown"/>
<TextBlock Width="300" Height="100" Name="textBlock1"/>
</StackPanel>
The following code behind creates the KeyDown event handler. If the key that is pressed is the Enter key, a message is displayed and you'll see a new line appended.
private void OnKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return)
{
MessageBox.Show($"You entered : {textBox1.Text}");
var sb = new StringBuilder();
sb.Append(textBox1.Text);
sb.AppendLine("");
textBox1.Text = sb.ToString();
textBox1.CaretIndex = textBox1.Text.Length;
}
}