In a ViewModel I have a Command, and in a View I have a button binded to that Command :
...
public Command SaveCommand { get; }
private async void Save(){
IsBusy = true;
Estatus = "Grabando...";
Task<bool> taskSaved = _negotiationRepo.SaveNegotiation(_negotiation, _following);
bool Saved = await taskSaved;
IsBusy = false;
if (Saved)
{
Estatus = "Saved";
await Application.Current.MainPage.DisplayAlert("Negotiation","Saved correctly","OK");
}
else
{
await Application.Current.MainPage.DisplayAlert("Negotiation", "Problem saving negotiation", "OK");
}
}
public NegotiationVM(Client client){
...
SaveCommand = new Command((Save),canExecute: ()=>!IsBusy);
...
}
In XAML View:
<Button Text="Save" BackgroundColor="#3276b1" TextColor="White" Command="{Binding SaveCommand}">
As you can see, I have a DisplayAlert in this ViewModel class. I'm not sure, but according to MVVM I shouldn't do this here, or at least not in that way. How can I properly display an alert or prompt after this command is fired?
I'm not using any MVVM Framework at this moment, most examples are focused in MVVM Light or Prism.