How to trigger a button click event when you press the enter button in C #

I am creating a login form for a Windows Phone application, I want to trigger a login button event when I press the enter button, ending the form.

Requirement: . When you press the enter button from the last text field on the login page, you must trigger the login button event.

Sample Code I know how to move from one text box to another by pressing the enter button as shown below

private void passkeydown(object sender, KeyEventArgs e)
{
  if (e.Key == Key.Enter)
 {
  nextfield .Focus();
  }
 }

But I do not know how to trigger a button click event here.

+4
source share
1 answer

Try the following:

if (e.Key == Key.Enter)
{
  LoginButton_Click(sender,e); //here LoginButton_Click is click eventhandler
}
+2
source

Source: https://habr.com/ru/post/1532118/


All Articles