// Click handler for the login button. private void LoginButtonClick(object sender, EventArgs e) { try { // Get information for the login. string username = _usernameTextbox.Text; string password = _passwordTextbox.Text; // Make sure all required info was entered. if (String.IsNullOrEmpty(username) || String.IsNullOrEmpty(password)) { throw new Exception("Please enter a username and password."); } // Create a new OnEnterCredentialsEventArgs object to store the information entered by the user. OnEnterCredentialsEventArgs credentialsEnteredArgs = new OnEnterCredentialsEventArgs(username, password); // Raise the OnLoginClicked event so the main activity can handle the event and try to authenticate with the credentials. OnLoginClicked?.Invoke(this, credentialsEnteredArgs); // Close the dialog. this.Dismiss(); } catch (Exception ex) { // Show the exception message (dialog will stay open so user can try again). AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this.Activity); alertBuilder.SetTitle("Error"); alertBuilder.SetMessage(ex.Message); alertBuilder.Show(); } }
private void buttonLogin_Click(object sender, EventArgs e) => OnLoginClicked?.Invoke(this, new LoginEventArgs { Login = textBoxLogin.Text, Password = textBoxPassword.Text });