I have a delete object command working in my ViewModel. The command is bound to the button. So far, so good. When I click the button the object is deleted from the db. Now, obviously, this needs to be validated, so I am using DisplayAlert to show a "Are you sure you want to delete?" to the user. This displays, but the item deletes anyway on the button click which makes sense. I am struggling to understand how to only run my command in the ViewModel if the user chooses "Yes".
XAML Button:
<Button Text="Delete player" Command="{Binding DeleteCommand}" Clicked="DeletePlayerEvent"></Button>
Clicked Event:
private async void DeletePlayerEvent(object sender, EventArgs e)
{
bool answer = await DisplayAlert("Notification", "Are you sure you want to delete this player?", "Yes", "No");
//if (answer == true)??????
// {
//Can I run the command from here?
//}
}
ViewModel Command
public Command DeleteCommand
{
get
{
return new Command(async () =>
{
var playerServices = new PlayerServices();
await playerServices.DeletePlayerAsync(_Player.Id);
});
}
}