Home > Enterprise >  Call method in View from ViewModel
Call method in View from ViewModel

Time:09-26

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.

CodePudding user response:

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);

  • Related