Hi @דני שטרית , Welcome to Microsoft Q&A,
When TextBox receives the KeyDown event and the Enter key is pressed, it calls the TextBox_KeyDown method, which in turn calls the Button_Click method, which triggers the button's Click event. You can modify the code in the Button_Click method as needed
<Grid>
<TextBox Name="textBox1" KeyDown="TextBox_KeyDown" Margin="26,30,277,311" RenderTransformOrigin="0.5,0.5" >
</TextBox>
<Button Content="OK" Click="Button_Click" Margin="30,178,285,187" Height="69" d:LayoutOverrides="VerticalAlignment" />
</Grid>
private void TextBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
Button_Click(sender, e);
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("Button Clicked!");
}
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.