Example #1
0
        static async void OnPageAlert(Page sender, AlertArguments options)
        {
            string content = options.Message ?? string.Empty;
            string title   = options.Title ?? string.Empty;

            var alertDialog = new ContentDialog
            {
                Content = content,
                Title   = title
            };

            if (options.Cancel != null)
            {
                alertDialog.SecondaryButtonText = options.Cancel;
            }

            if (options.Accept != null)
            {
                alertDialog.PrimaryButtonText = options.Accept;
            }

            while (s_currentAlert != null)
            {
                await s_currentAlert;
            }

            s_currentAlert = ShowAlert(alertDialog);
            options.SetResult(await s_currentAlert);
            s_currentAlert = null;
        }
Example #2
0
        void PresentAlert(AlertArguments arguments)
        {
            var window = new UIWindow {
                BackgroundColor = Colors.Transparent.ToUIColor()
            };

            var alert    = UIAlertController.Create(arguments.Title, arguments.Message, UIAlertControllerStyle.Alert);
            var oldFrame = alert.View.Frame;

            alert.View.Frame = new CGRect(oldFrame.X, oldFrame.Y, oldFrame.Width, oldFrame.Height - _alertPadding * 2);

            if (arguments.Cancel != null)
            {
                alert.AddAction(CreateActionWithWindowHide(arguments.Cancel, UIAlertActionStyle.Cancel,
                                                           () => arguments.SetResult(false), window));
            }

            if (arguments.Accept != null)
            {
                alert.AddAction(CreateActionWithWindowHide(arguments.Accept, UIAlertActionStyle.Default,
                                                           () => arguments.SetResult(true), window));
            }

            PresentPopUp(window, alert);
        }
Example #3
0
        public void DisplayAlert()
        {
            var page = new ContentPage()
            {
                IsPlatformEnabled = true
            };

            AlertArguments args = null;

            MessagingCenter.Subscribe(this, Page.AlertSignalName, (Page sender, AlertArguments e) => args = e);

            var task = page.DisplayAlert("Title", "Message", "Accept", "Cancel");

            Assert.AreEqual("Title", args.Title);
            Assert.AreEqual("Message", args.Message);
            Assert.AreEqual("Accept", args.Accept);
            Assert.AreEqual("Cancel", args.Cancel);

            bool completed    = false;
            var  continueTask = task.ContinueWith(t => completed = true);

            args.SetResult(true);
            continueTask.Wait();
            Assert.True(completed);
        }
        static async void OnPageAlert(Page sender, AlertArguments options)
        {
            string content = options.Message ?? string.Empty;
            string title   = options.Title ?? string.Empty;

            var alertDialog = new ContentDialog
            {
                Content = content,
                Title   = title
            };

            if (options.Cancel != null)
            {
                alertDialog.SecondaryButtonText = options.Cancel;
            }

            if (options.Accept != null)
            {
                alertDialog.PrimaryButtonText = options.Accept;
            }

            ContentDialogResult result = await alertDialog.ShowAsync();

            if (result == ContentDialogResult.Secondary)
            {
                options.SetResult(false);
            }
            else if (result == ContentDialogResult.Primary)
            {
                options.SetResult(true);
            }
        }
Example #5
0
        async void OnPageAlert(Page sender, AlertArguments options)
        {
            string content = options.Message ?? options.Title ?? string.Empty;

            FormsContentDialog dialog = new FormsContentDialog();

            if (options.Message == null || options.Title == null)
            {
                dialog.Content = content;
            }
            else
            {
                dialog.Title   = options.Title;
                dialog.Content = options.Message;
            }

            if (options.Accept != null)
            {
                dialog.IsPrimaryButtonEnabled = true;
                dialog.PrimaryButtonText      = options.Accept;
            }

            if (options.Cancel != null)
            {
                dialog.IsSecondaryButtonEnabled = true;
                dialog.SecondaryButtonText      = options.Cancel;
            }

            var dialogResult = await dialog.ShowAsync();

            options.SetResult(dialogResult == LightContentDialogResult.Primary);
        }
Example #6
0
        static async void OnPageAlert(Page sender, AlertArguments options)
        {
            string content = options.Message ?? string.Empty;
            string title   = options.Title ?? string.Empty;

            var alertDialog = new AlertDialog
            {
                Content = content,
                Title   = title,
                VerticalScrollBarVisibility = Windows.UI.Xaml.Controls.ScrollBarVisibility.Auto
            };

            if (options.Cancel != null)
            {
                alertDialog.SecondaryButtonText = options.Cancel;
            }

            if (options.Accept != null)
            {
                alertDialog.PrimaryButtonText = options.Accept;
            }

            var currentAlert = s_currentAlert;

            while (currentAlert != null)
            {
                await currentAlert;
                currentAlert = s_currentAlert;
            }

            s_currentAlert = ShowAlert(alertDialog);
            options.SetResult(await s_currentAlert.ConfigureAwait(false));
            s_currentAlert = null;
        }
Example #7
0
        public static void ShowAlert(PlatformRenderer platformRender, AlertArguments arguments)
        {
            MessageDialog messageDialog = new MessageDialog(
                platformRender.Toplevel as Window,
                DialogFlags.DestroyWithParent,
                MessageType.Other,
                GetAlertButtons(arguments),
                arguments.Message);

            SetDialogTitle(arguments.Title, messageDialog);
            SetButtonText(arguments.Accept, ButtonsType.Ok, messageDialog);
            SetButtonText(arguments.Cancel, ButtonsType.Cancel, messageDialog);

            ResponseType result = (ResponseType)messageDialog.Run();

            if (result == ResponseType.Ok)
            {
                arguments.SetResult(true);
            }
            else
            {
                arguments.SetResult(false);
            }

            messageDialog.Destroy();
        }
Example #8
0
        async void OnPageAlert(Page sender, AlertArguments options)
        {
            string content = options.Message ?? options.Title ?? string.Empty;

            MessageDialog dialog;

            if (options.Message == null || options.Title == null)
            {
                dialog = new MessageDialog(content);
            }
            else
            {
                dialog = new MessageDialog(options.Message, options.Title);
            }

            if (options.Accept != null)
            {
                dialog.Commands.Add(new UICommand(options.Accept));
                dialog.DefaultCommandIndex = (uint)dialog.Commands.Count - 1;
            }

            if (options.Cancel != null)
            {
                dialog.Commands.Add(new UICommand(options.Cancel));
                dialog.CancelCommandIndex = 0;
            }

            IUICommand command = await dialog.ShowAsync();

            options.SetResult(command.Label == options.Accept);
        }
Example #9
0
        /// <summary>
        /// Sends the alert.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="caption">The caption.</param>
        /// <param name="message">The message.</param>
        /// <param name="positiveButton">The positive button.</param>
        /// <param name="negativeButton">The negative button.</param>
        /// <returns>System.Threading.Tasks.TaskCompletionSource&lt;System.Boolean&gt;.</returns>
        public static async Task <bool> SendAlertAsync(Page sender, string caption, string message, string positiveButton, string negativeButton)
        {
            var argument = new AlertArguments(caption, message, positiveButton, negativeButton);

            SendAlertMessage(sender, argument);
            return(await argument.Result.Task);
        }
Example #10
0
        public void AlertArgumentsConstructor()
        {
            tlog.Debug(tag, $"AlertArgumentsConstructor START");

            var testingTarget = new AlertArguments("AlertArguments", "AlertArguments", "ACCEPT", "CANCEL");

            Assert.IsNotNull(testingTarget, "Can't create success object AlertArguments.");
            Assert.IsInstanceOf <AlertArguments>(testingTarget, "Should return AlertArguments instance.");

            tlog.Debug(tag, "Accept  : " + testingTarget.Accept);
            tlog.Debug(tag, "Cancel  : " + testingTarget.Cancel);
            tlog.Debug(tag, "Message   : " + testingTarget.Message);
            tlog.Debug(tag, "Result  : " + testingTarget.Result);
            tlog.Debug(tag, "Title   : " + testingTarget.Title);

            try
            {
                testingTarget.SetResult(true);
            }
            catch (Exception e)
            {
                tlog.Debug(tag, e.Message.ToString());
                Assert.Fail("Caught Exception : Failed!");
            }

            tlog.Debug(tag, $"AlertArgumentsConstructor END");
        }
Example #11
0
            async void OnAlertRequested(Page sender, AlertArguments arguments)
            {
                string content = arguments.Message ?? string.Empty;
                string title   = arguments.Title ?? string.Empty;

                var alertDialog = new AlertDialog
                {
                    Content = content,
                    Title   = title,
                    VerticalScrollBarVisibility = UI.Xaml.Controls.ScrollBarVisibility.Auto
                };

                if (arguments.FlowDirection == FlowDirection.RightToLeft)
                {
                    alertDialog.FlowDirection = UI.Xaml.FlowDirection.RightToLeft;
                }
                else if (arguments.FlowDirection == FlowDirection.LeftToRight)
                {
                    alertDialog.FlowDirection = UI.Xaml.FlowDirection.LeftToRight;
                }
                else
                {
                    if (sender is IVisualElementController visualElementController)
                    {
                        if (visualElementController.EffectiveFlowDirection.IsRightToLeft())
                        {
                            alertDialog.FlowDirection = UI.Xaml.FlowDirection.RightToLeft;
                        }
                        else if (visualElementController.EffectiveFlowDirection.IsLeftToRight())
                        {
                            alertDialog.FlowDirection = UI.Xaml.FlowDirection.LeftToRight;
                        }
                    }
                }

                if (arguments.Cancel != null)
                {
                    alertDialog.SecondaryButtonText = arguments.Cancel;
                }

                if (arguments.Accept != null)
                {
                    alertDialog.PrimaryButtonText = arguments.Accept;
                }

                // This is a temporary workaround
                alertDialog.XamlRoot = Window.Content.XamlRoot;

                var currentAlert = CurrentAlert;

                while (currentAlert != null)
                {
                    await currentAlert;
                    currentAlert = CurrentAlert;
                }

                CurrentAlert = ShowAlert(alertDialog);
                arguments.SetResult(await CurrentAlert.ConfigureAwait(false));
                CurrentAlert = null;
            }
Example #12
0
        public Task <bool> DisplayAlert(string Title, string Message, string Ok, string Cancel)
        {
            frame.Visibility = Visibility.Visible;
            var args  = new AlertArguments(Title, Message, Ok, Cancel);
            var alert = new AlertDialog(args, CloseAlert);

            frame.Navigate(alert);
            return(args.Result.Task);
        }
Example #13
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="sender">Calling page</param>
    /// <param name="arguments"></param>
    private static void PatchDisplayAlert(Page sender, AlertArguments arguments)
    {
        //DisplayAlert on z-index
        var element = Navigation.CurrentPage.GetOouiElement();

        if (element.GetAttribute("style") == null)
        {
            element.SetAttribute("style", "{z-index:9999;}");
        }
    }
		void Button_Clicked (object sender, EventArgs e)
		{
			AlertArguments arg = new AlertArguments { 
				Title = "Title",
				Message = "Everything is customized!!",
				Accept = "Ok",
				Cancel = "Cancel"
			};

			MessagingCenter.Send (this, "DisplayAlert",arg);
		}			
Example #15
0
        static async void OnPageAlert(Page sender, AlertArguments options)
        {
            string content = options.Message ?? string.Empty;
            string title   = options.Title ?? string.Empty;

            var alertDialog = new AlertDialog
            {
                Content = content,
                Title   = title,
                VerticalScrollBarVisibility = Microsoft.UI.Xaml.Controls.ScrollBarVisibility.Auto
            };

            if (options.FlowDirection == FlowDirection.RightToLeft)
            {
                alertDialog.FlowDirection = Microsoft.UI.Xaml.FlowDirection.RightToLeft;
            }
            else if (options.FlowDirection == FlowDirection.LeftToRight)
            {
                alertDialog.FlowDirection = Microsoft.UI.Xaml.FlowDirection.LeftToRight;
            }
            else
            {
                if ((sender as IVisualElementController).EffectiveFlowDirection.IsRightToLeft())
                {
                    alertDialog.FlowDirection = WFlowDirection.RightToLeft;
                }
                else if ((sender as IVisualElementController).EffectiveFlowDirection.IsLeftToRight())
                {
                    alertDialog.FlowDirection = WFlowDirection.LeftToRight;
                }
            }

            if (options.Cancel != null)
            {
                alertDialog.SecondaryButtonText = options.Cancel;
            }

            if (options.Accept != null)
            {
                alertDialog.PrimaryButtonText = options.Accept;
            }

            var currentAlert = s_currentAlert;

            while (currentAlert != null)
            {
                await currentAlert;
                currentAlert = s_currentAlert;
            }

            s_currentAlert = ShowAlert(alertDialog);
            options.SetResult(await s_currentAlert.ConfigureAwait(false));
            s_currentAlert = null;
        }
Example #16
0
File: Page.cs Project: yl33/TizenFX
        public Task <bool> DisplayAlert(string title, string message, string accept, string cancel)
        {
            if (string.IsNullOrEmpty(cancel))
            {
                throw new ArgumentNullException("cancel");
            }

            var args = new AlertArguments(title, message, accept, cancel);

            MessagingCenter.Send(this, AlertSignalName, args);
            return(args.Result.Task);
        }
Example #17
0
            void OnAlertRequested(IView sender, AlertArguments arguments)
            {
                // Verify that the page making the request is part of this activity
                if (!PageIsInThisContext(sender))
                {
                    return;
                }

                int messageID = 16908299;
                var alert     = new DialogBuilder(Activity).Create();

                if (alert == null)
                {
                    return;
                }

                if (alert.Window != null)
                {
                    if (arguments.FlowDirection == FlowDirection.MatchParent && sender is IView view)
                    {
                        alert.Window.DecorView.UpdateFlowDirection(view);
                    }
                    else if (arguments.FlowDirection == FlowDirection.LeftToRight)
                    {
                        alert.Window.DecorView.LayoutDirection = LayoutDirection.Ltr;
                    }
                    else if (arguments.FlowDirection == FlowDirection.RightToLeft)
                    {
                        alert.Window.DecorView.LayoutDirection = LayoutDirection.Rtl;
                    }
                }

                alert.SetTitle(arguments.Title);
                alert.SetMessage(arguments.Message);
                if (arguments.Accept != null)
                {
                    alert.SetButton((int)DialogButtonType.Positive, arguments.Accept, (o, args) => arguments.SetResult(true));
                }
                alert.SetButton((int)DialogButtonType.Negative, arguments.Cancel, (o, args) => arguments.SetResult(false));
                alert.SetCancelEvent((o, args) => { arguments.SetResult(false); });
                alert.Show();

                TextView textView = (TextView)alert.findViewByID(messageID);

                textView.TextDirection = GetTextDirection(sender, arguments.FlowDirection);


                if (alert.GetButton((int)DialogButtonType.Negative).Parent is AView parentView)
                {
                    parentView.LayoutDirection = GetLayoutDirection(sender, arguments.FlowDirection);
                }
            }
Example #18
0
        void OnAlertRequest(Page sender, AlertArguments arguments)
        {
            // Verify that the page making the request is child of this platform
            if (!PageIsInThisContext(sender))
            {
                return;
            }

            var alert = Dialog.CreateDialog(MauiContext.GetPlatformParent(), (arguments.Accept != null));

            alert.Title = arguments.Title;
            var message = arguments.Message?.Replace("&", "&amp;", StringComparison.Ordinal).Replace("<", "&lt;", StringComparison.Ordinal).Replace(">", "&gt;", StringComparison.Ordinal).Replace(Environment.NewLine, "<br>", StringComparison.Ordinal);

            alert.Message = message;

            var cancel = new EButton(alert)
            {
                Text = arguments.Cancel
            };

            alert.NegativeButton = cancel;
            cancel.Clicked      += (s, evt) =>
            {
                arguments.SetResult(false);
                alert.Dismiss();
            };

            if (arguments.Accept != null)
            {
                var ok = new EButton(alert)
                {
                    Text = arguments.Accept
                };
                alert.NeutralButton = ok;
                ok.Clicked         += (s, evt) =>
                {
                    arguments.SetResult(true);
                    alert.Dismiss();
                };
            }

            alert.BackButtonPressed += (s, evt) =>
            {
                arguments.SetResult(false);
                alert.Dismiss();
            };

            alert.Show();
            _alerts.Add(alert);
            alert.Dismissed += (s, e) => _alerts.Remove(alert);
        }
Example #19
0
        void AlertSignalNameHandler(Page sender, AlertArguments arguments)
        {
            // Verify that the page making the request is child of this platform
            if (!PageIsChildOfPlatform(sender))
            {
                return;
            }

            Native.Dialog alert = Native.Dialog.CreateDialog(Forms.NativeParent, (arguments.Accept != null));

            alert.Title = arguments.Title;
            var message = arguments.Message.Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;").Replace(Environment.NewLine, "<br>");

            alert.Message = message;

            EButton cancel = new EButton(alert)
            {
                Text = arguments.Cancel
            };

            alert.NegativeButton = cancel;
            cancel.Clicked      += (s, evt) =>
            {
                arguments.SetResult(false);
                alert.Dismiss();
            };

            if (arguments.Accept != null)
            {
                EButton ok = new EButton(alert)
                {
                    Text = arguments.Accept
                };
                alert.NeutralButton = ok;
                ok.Clicked         += (s, evt) =>
                {
                    arguments.SetResult(true);
                    alert.Dismiss();
                };
            }

            alert.BackButtonPressed += (s, evt) =>
            {
                arguments.SetResult(false);
                alert.Dismiss();
            };

            alert.Show();
            _alerts.Add(alert);
            alert.Dismissed += (s, e) => _alerts.Remove(alert);
        }
        void OnAlertRequested(Page sender, AlertArguments arguments)
        {
            AlertDialog alert = new AlertDialog.Builder(this).Create();

            alert.SetTitle(arguments.Title);
            alert.SetMessage(arguments.Message);
            if (arguments.Accept != null)
            {
                alert.SetButton((int)DialogButtonType.Positive, arguments.Accept, (o, args) => arguments.SetResult(true));
            }
            alert.SetButton((int)DialogButtonType.Negative, arguments.Cancel, (o, args) => arguments.SetResult(false));
            alert.CancelEvent += (o, args) => { arguments.SetResult(false); };
            alert.Show();
        }
Example #21
0
        void Present8Alert(AlertArguments arguments)
        {
            var alert    = UIAlertController.Create(arguments.Title, arguments.Message, UIAlertControllerStyle.Alert);
            var oldFrame = alert.View.Frame;

            alert.View.Frame = new RectangleF(oldFrame.X, oldFrame.Y, oldFrame.Width, oldFrame.Height - _alertPadding * 2);
            alert.AddAction(UIAlertAction.Create(arguments.Cancel, UIAlertActionStyle.Cancel, a => arguments.SetResult(false)));
            if (arguments.Accept != null)
            {
                alert.AddAction(UIAlertAction.Create(arguments.Accept, UIAlertActionStyle.Default, a => arguments.SetResult(true)));
            }
            var page = _modals.Any() ? _modals.Last() : Page;
            var vc   = GetRenderer(page).ViewController;

            vc.PresentViewController(alert, true, null);
        }
Example #22
0
        void PresentPre8Alert(AlertArguments arguments)
        {
            UIAlertView alertView;

            if (arguments.Accept != null)
            {
                alertView = new UIAlertView(arguments.Title, arguments.Message, null, arguments.Cancel, arguments.Accept);
            }
            else
            {
                alertView = new UIAlertView(arguments.Title, arguments.Message, null, arguments.Cancel);
            }

            alertView.Dismissed += (o, args) => arguments.SetResult(args.ButtonIndex != 0);
            alertView.Show();
        }
 public AlertDialog(AlertArguments arguments, Action close)
 {
     InitializeComponent();
     title.Text     = arguments.Title;
     message.Text   = arguments.Message;
     accept.Content = arguments.Accept;
     accept.Click  += (sender, args) =>
     {
         arguments.SetResult(true);
         close?.Invoke();
     };
     cancel.Content = arguments.Cancel;
     cancel.Click  += (sender, args) =>
     {
         arguments.SetResult(false);
         close?.Invoke();
     };
 }
Example #24
0
        static async void OnPageAlert(object sender, AlertArguments options)
        {
            string content = options.Message ?? options.Title ?? string.Empty;

            MessageDialog dialog;

            if (options.Message == null || options.Title == null)
            {
                dialog = new MessageDialog(content);
            }
            else
            {
                dialog = new MessageDialog(options.Message, options.Title);
            }

            if (options.Accept != null)
            {
                dialog.Commands.Add(new UICommand(options.Accept));
                dialog.DefaultCommandIndex = 0;
            }

            if (options.Cancel != null)
            {
                dialog.Commands.Add(new UICommand(options.Cancel));
                dialog.CancelCommandIndex = (uint)dialog.Commands.Count - 1;
            }

            if (Device.IsInvokeRequired)
            {
                Device.BeginInvokeOnMainThread(async() =>
                {
                    IUICommand command = await dialog.ShowAsyncQueue();
                    options.SetResult(command.Label == options.Accept);
                });
            }
            else
            {
                IUICommand command = await dialog.ShowAsyncQueue();

                options.SetResult(command.Label == options.Accept);
            }
        }
Example #25
0
        static void AlertSignalNameHandler(Page sender, AlertArguments arguments)
        {
            Native.Dialog alert = new Native.Dialog(Forms.Context.MainWindow);
            alert.Title = arguments.Title;
            var message = arguments.Message.Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;").Replace(Environment.NewLine, "<br>");

            alert.Text = message;

            EButton cancel = new EButton(alert)
            {
                Text = arguments.Cancel
            };

            alert.NegativeButton = cancel;
            cancel.Clicked      += (s, evt) =>
            {
                arguments.SetResult(false);
                alert.Dismiss();
            };

            if (arguments.Accept != null)
            {
                EButton ok = new EButton(alert)
                {
                    Text = arguments.Accept
                };
                alert.NeutralButton = ok;
                ok.Clicked         += (s, evt) =>
                {
                    arguments.SetResult(true);
                    alert.Dismiss();
                };
            }

            alert.BackButtonPressed += (s, evt) =>
            {
                arguments.SetResult(false);
                alert.Dismiss();
            };

            alert.Show();
        }
        void OnPageAlert(Page sender, AlertArguments options)
        {
            string content = options.Message ?? options.Title ?? string.Empty;

            if (options.Message == null || options.Title == null)
            {
                MessageBox.Query(48, 6, string.Empty, content, new string[] { options.Cancel });
            }
            else
            {
                var buttons = new string[] { options.Cancel };

                if (!string.IsNullOrEmpty(options.Accept))
                {
                    buttons = new string[] { options.Accept, options.Cancel };
                }

                MessageBox.Query(48, 6, options.Title, content, buttons);
            }
        }
Example #27
0
        public Task <bool> DisplayAlert(string title, string message, string accept, string cancel)
        {
            if (string.IsNullOrEmpty(cancel))
            {
                throw new ArgumentNullException("cancel");
            }

            var args = new AlertArguments(title, message, accept, cancel);

            if (IsPlatformEnabled)
            {
                MessagingCenter.Send(this, AlertSignalName, args);
            }
            else
            {
                _pendingActions.Add(() => MessagingCenter.Send(this, AlertSignalName, args));
            }

            return(args.Result.Task);
        }
Example #28
0
            void OnAlertRequested(Page sender, AlertArguments arguments)
            {
                // Verify that the page making the request is part of this activity
                if (!PageIsInThisContext(sender))
                {
                    return;
                }

                var alert = new DialogBuilder(Activity).Create();

                alert.SetTitle(arguments.Title);
                alert.SetMessage(arguments.Message);
                if (arguments.Accept != null)
                {
                    alert.SetButton((int)DialogButtonType.Positive, arguments.Accept, (o, args) => arguments.SetResult(true));
                }
                alert.SetButton((int)DialogButtonType.Negative, arguments.Cancel, (o, args) => arguments.SetResult(false));
                alert.SetCancelEvent((o, args) => { arguments.SetResult(false); });
                alert.Show();
            }
Example #29
0
            void PresentAlert(AlertArguments arguments)
            {
                var alert    = UIAlertController.Create(arguments.Title, arguments.Message, UIAlertControllerStyle.Alert);
                var oldFrame = alert.View.Frame;

                alert.View.Frame = new RectF((float)oldFrame.X, (float)oldFrame.Y, (float)oldFrame.Width, (float)oldFrame.Height - AlertPadding * 2);

                if (arguments.Cancel != null)
                {
                    alert.AddAction(UIAlertAction.Create(arguments.Cancel, UIAlertActionStyle.Cancel,
                                                         _ => arguments.SetResult(false)));
                }

                if (arguments.Accept != null)
                {
                    alert.AddAction(UIAlertAction.Create(arguments.Accept, UIAlertActionStyle.Default,
                                                         _ => arguments.SetResult(true)));
                }

                PresentPopUp(Window, alert);
            }
Example #30
0
        private static ButtonsType GetAlertButtons(AlertArguments arguments)
        {
            bool hasAccept = !string.IsNullOrEmpty(arguments.Accept);
            bool hasCancel = !string.IsNullOrEmpty(arguments.Cancel);

            ButtonsType type = ButtonsType.None;

            if (hasAccept && hasCancel)
            {
                type = ButtonsType.OkCancel;
            }
            else if (hasAccept && !hasCancel)
            {
                type = ButtonsType.Ok;
            }
            else if (!hasAccept && hasCancel)
            {
                type = ButtonsType.Cancel;
            }

            return(type);
        }
Example #31
0
        /// <include file="../../docs/Microsoft.Maui.Controls/Page.xml" path="//Member[@MemberName='DisplayAlert'][2]/Docs" />
#pragma warning disable CS1573 // Parameter has no matching param tag in the XML comment (but other parameters do)
        public Task <bool> DisplayAlert(string title, string message, string accept, string cancel, FlowDirection flowDirection)
#pragma warning restore CS1573 // Parameter has no matching param tag in the XML comment (but other parameters do)
        {
            if (string.IsNullOrEmpty(cancel))
            {
                throw new ArgumentNullException("cancel");
            }

            var args = new AlertArguments(title, message, accept, cancel);

            args.FlowDirection = flowDirection;

            if (IsPlatformEnabled)
            {
                MessagingCenter.Send(this, AlertSignalName, args);
            }
            else
            {
                _pendingActions.Add(() => MessagingCenter.Send(this, AlertSignalName, args));
            }

            return(args.Result.Task);
        }
Example #32
0
		async void OnPageAlert(Page sender, AlertArguments options)
		{
			string content = options.Message ?? options.Title ?? string.Empty;

			MessageDialog dialog;
			if (options.Message == null || options.Title == null)
				dialog = new MessageDialog(content);
			else
				dialog = new MessageDialog(options.Message, options.Title);

			if (options.Accept != null)
			{
				dialog.Commands.Add(new UICommand(options.Accept));
				dialog.DefaultCommandIndex = (uint)dialog.Commands.Count - 1;
			}

			if (options.Cancel != null)
			{
				dialog.Commands.Add(new UICommand(options.Cancel));
				dialog.CancelCommandIndex = 0;
			}

			IUICommand command = await dialog.ShowAsync();
			options.SetResult(command.Label == options.Accept);
		}