I want to check if a TextBox is empty and then give a error warning to the user using a MessageDialog. My problem is that the async method needs a void return type so I cannot use a bool to check is CheckEmpty returns a true or false. How can I stop the code in AddButton_Click after CheckEmpty() when this gives an error/message warning?
public void AddButton_Click(object sender, RoutedEventArgs e)
{
if (roleComboBox.SelectionBoxItem.Equals("Player"))
{
CheckEmpty();
memberID++;
Player player = new Player(memberID, team, firstName, lastName, age, salary, yearsActive, position, minutesPerGame);
players.Add(player);
idBox = idComboBox;
idBox.Items.Add(memberID);
PrintList();
}
}
private async void CheckEmpty()
{
if (firstNameTextBox.Text == "") //if (String.IsNullOrEmpty(firstNameTextBox.Text)
{
var messageDialog = new MessageDialog("Text here");
messageDialog.Commands.Add(new UICommand("Try again"));
await messageDialog.ShowAsync();
}