Eve
Eve

Reputation: 101

Cancel alert in UserDialogs

I would like to make a simple alert with two options , using UserDialogs package.

I can't figure out how to add a cancel option in UserDialogs...

var check =  await UserDialogs.Instance.AlertAsync("title", "message", "ok","????");
if (check)
  await NavigationService.NavigateAsync("Page1");
else 
  await NavigationService.NavigateAsync("Page2");

Upvotes: 0

Views: 1511

Answers (3)

Samir Dahal
Samir Dahal

Reputation: 19

I have done something like this: In App.xaml.cs class

public static IUserDialogs UserDialogs => Acr.UserDialogs.UserDialogs.Instance;

And whenever you need just use like this: Do not trust the string. Check the OK, if it is false, user has declined.

App.UserDialogs.Prompt(new PromptConfig
        {
            CancelText = "Cancel",
            OkText = "Add",
            InputType = InputType.Url,
            Placeholder = "Custom URL",
            Title = "Enter custom url",
            IsCancellable = true,
            OnAction = async (result) =>
            {
                //user declined
                if (result.Ok is false) return;

                //User pressed ok button
            },
        });

Upvotes: 0

Arvind Chourasiya
Arvind Chourasiya

Reputation: 17422

As @AndroDevil commented, You can use this code to have Cancel and Ok button on Alert

btnNewPage.Clicked +=async delegate
{
   string action = await DisplayActionSheet("title", "Cancel", "Ok");
   if (action == "Ok")
   {
       //Ok
   }
   else if (action == "Cancel")
   {
       //Cancel
   }
};

Update: As per your comment if you need it using UserDialog

var check = await UserDialogs.Instance.ConfirmAsync("message", "title" , "Ok","Cancel");
if (check)
  await NavigationService.NavigateAsync("Page1");
else 
  await NavigationService.NavigateAsync("Page2");

Upvotes: 5

Ramu Krishna
Ramu Krishna

Reputation: 11

You can use DisplayAlert instead, in Xaml.cs file.

var response = await DisplayAlert("Title", "Message", "Ok", "Cancel");
if (response == true) {
   //Yes action
} else {
   //No action
}

Upvotes: 0

Related Questions