How to convert AlertDialog to Snackbar?

SteveRussellSteveRussell Member ✭✭✭
edited May 2018 in Xamarin.Forms

I have the following in my Xamarin.Forms project:

`if (ShouldShowRequestPermissionRationale(permission))
{
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.SetTitle("Location permission needed");
alert.SetPositiveButton("Allow", (senderAlert, args) =>
{
RequestPermissions(PermissionsGroupLocation, RequestLocationId);
});

            alert.SetNegativeButton("Cancel", (senderAlert, args) =>
            {
                Toast.MakeText(this, "Cancelled", ToastLength.Short).Show();
            });

            Dialog dialog = alert.Create();
            dialog.Show();


            return;
        }`

I'd like to make it into a snackbar so it doesn't block the main page and dismisses itself after a few seconds

The main problem is that Snackbar.Make() takes a view as its first parameter but I'm using Xamarin Forms

Best Answer

Answers

  • Saraswati_ChandraSaraswati_Chandra USMember ✭✭✭

    I think you should go with a cleaner/better approach, i.e, using DependencyServices

  • SteveRussellSteveRussell Member ✭✭✭

    How can I use DependencyServices?

Sign In or Register to comment.