private void OnButtonKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { currentTextBox = (CurrentTextBox)(int)currentTextBox + 1; switch (currentTextBox) { case CurrentTextBox.email: emailTextBox.Focus(); break; case CurrentTextBox.phone: phoneNumberTextBox.Focus(); break; case CurrentTextBox.note: notesTextBox.Focus(); break; default: saveNewContact(); this.Close(); break; } } else if (e.Key == Key.Escape) { this.Close(); } }
public NewContactWindow() { InitializeComponent(); //Registers the keyboard listener event this.KeyDown += new KeyEventHandler(OnButtonKeyDown); //Lets the window open in the middle of the main window Owner = Application.Current.MainWindow; WindowStartupLocation = WindowStartupLocation.CenterOwner; //Sets automatical keyboard focus nameTextBox.Focus(); currentTextBox = CurrentTextBox.name; }