Example #1
0
            void AlertSignalNameHandler(Page sender, AlertArguments arguments)
            {
                //Managing buttons logic behavior with Xamarin.Forms
                List <string> buttons = new List <string>();

                if (!string.IsNullOrEmpty(arguments.Accept))
                {
                    buttons.Add(arguments.Accept);
                }
                buttons.Add(arguments.Cancel);

                Device.BeginInvokeOnMainThread(async() => {
                    var messageBoxResult = await Electron.Dialog.ShowMessageBoxAsync(new ElectronNET.API.Entities.MessageBoxOptions(arguments.Message)
                    {
                        Title   = arguments.Title,
                        Buttons = buttons.ToArray(),
                        Type    = ElectronNET.API.Entities.MessageBoxType.none,
                        NoLink  = true
                    });

                    bool isOk = true;

                    //If buttons count equal 1, we only have a cancel button
                    //If we have more than 1 button but the Response index is the last button item, then it's a cancel button value
                    if (buttons.Count == 1 || buttons.Count > 1 && messageBoxResult.Response == buttons.Count - 1)
                    {
                        isOk = false;
                    }

                    arguments.SetResult(isOk);
                });
            }
Example #2
0
            void AlertSignalNameHandler(Page sender, AlertArguments arguments)
            {
                //Electron documentation about dialog: https://github.com/electron/electron/blob/v5.0.10/docs/api/dialog.md

                var applicationRef = DotNetObjectReference.Create(new ElectronBridge(this));
                var alertRef       = DotNetObjectReference.Create(arguments);

                BlazorMobileComponent.GetJSRuntime().InvokeAsync <bool>("BlazorMobileElectron.AlertDialog", applicationRef, alertRef, arguments.Title, arguments.Message, arguments.Accept, arguments.Cancel);
            }
Example #3
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);

            MessagingCenter.Send(this, AlertSignalName, args);
            return(args.Result.Task);
        }
Example #4
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 #5
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);
			MessagingCenter.Send(this, AlertSignalName, args);
			return args.Result.Task;
		}
Example #6
0
 public void OnAlertSignalResult(AlertArguments arguments, bool isOk)
 {
     arguments.SetResult(isOk);
 }