Beispiel #1
0
        public static Task <bool?> ShowConfirm(this Context context, string title, string message, string positiveBtn = "OK", string negativeBtn = "Cancel")
        {
            ManualResetEvent handle = new ManualResetEvent(false);

            bool?result = null;

            var builder = new AlertDialog.Builder(context);

            if (title != null)
            {
                builder.SetTitle(title);
            }

            if (message != null)
            {
                if (message.Contains("<") || message.Contains(">"))
                {
                    builder.SetHtml(message);
                }
                else
                {
                    builder.SetMessage(message);
                }
            }

            if (positiveBtn != null)
            {
                builder.SetPositiveButton(positiveBtn, delegate { result = true; });
            }

            if (negativeBtn != null)
            {
                builder.SetNegativeButton(negativeBtn, delegate { result = false; });
            }

            var dlg = builder.Create();

            dlg.Show();

            dlg.DismissEvent += delegate
            {
                handle.Set();
            };

            return(Task.Run(() =>
            {
                handle.WaitOne();
                return result;
            }));
        }