Think_Twice
Think_Twice

Reputation: 323

Call method in View from ViewModel

I am starting to learn Xamarin, so I am a noob.

I am trying to show a SnackBar or Toast using the Xamarin.CommunityToolkit.Extensions NuGet Package.

I can't seem to find a way to show a Toast or Snackbar in the ViewModel. The only way I found to display it was in the View.xaml.cs.

I created a method ShowToast() in my View.xaml.cs. I would like to know how do I call the ShowToast() method in my ViewModel.cs?

Thanks in advance.

Upvotes: 0

Views: 750

Answers (1)

Juan Sturla
Juan Sturla

Reputation: 1304

From your View model you can call

Not only for showing the snackbar,but also to handle navigation

await Application.Current.MainPage.DisplaySnackbarAsync(message, actionButtonText, action, duration);

Upvotes: 1

Related Questions