async void OnDeleteButtonClicked(object sender, EventArgs e) { bool answer = await DisplayAlert("Confirmation", "Are you sure you want to delete?", "Yes", "No"); if (answer) { // Delete the item } }
async void OnLoginButtonClicked(object sender, EventArgs e) { if (string.IsNullOrEmpty(usernameEntry.Text) || string.IsNullOrEmpty(passwordEntry.Text)) { await DisplayAlert("Error", "Username and password are required.", "OK"); } else { // Authenticate the user } }This code example displays an alert dialog with the message "Username and password are required." if either the username or password entry fields are empty. If the user taps the "OK" button, the alert dialog will disappear. Package library: Xamarin.Forms