Forum Xamarin.Forms

How to evaluate the DisplayAlert return when using MessageCenter

MANIKANTA_GMANIKANTA_G INMember ✭✭
edited September 2018 in Xamarin.Forms

For normally we use,
bool res = await this.pg.DisplayAlert("Attention", "identifier", "S'identifier", "Annuler");

But I am using MessagingCenter.Send<LoginViewModel, string>(this, "Hi", "Title"); from ViewModel. I have two buttons. If user clicks on Ok or Cancel button how can i get that response.

MessagingCenter.Subscribe<LoginViewModel, string>(this, "Hi", (sender, arg) => {

        UIAlertController vc = UIAlertController.Create("", arg, UIAlertControllerStyle.Alert);
        UIAlertAction action1 = UIAlertAction.Create("OK", UIAlertActionStyle.Default, null);
        UIAlertAction action = UIAlertAction.Create("Cancel", UIAlertActionStyle.Destructive, null);
        vc.AddAction(action);
        vc.AddAction(action1);
            var window = UIApplication.SharedApplication.KeyWindow;
            window.RootViewController.PresentViewController(vc, true, null);
        });        
Tagged:

Best Answer

Answers

Sign In or Register to comment.