Exemple #1
0
 public ModalDialogModel(Type dialogComponentType, string title, ModalDialogParameters parameters, ModalDialogOptions options)
 {
     this.TaskSource          = new TaskCompletionSource <ModalDialogResult>();
     this.DialogComponentType = dialogComponentType;
     this.Title      = title;
     this.Parameters = parameters;
     this.Options    = options;
 }
        public void Close(bool success, ModalDialogParameters returnParameters)
        {
            returnParameters = returnParameters ?? new ModalDialogParameters();

            ModalDialogModel closingDialogWindow = _dialogs.Pop();

            closingDialogWindow.TaskSource.SetResult(new ModalDialogResult(success, returnParameters));
            OnChanged();
        }
        /// <summary>
        /// Shows the Data Input Form in a modal dialog container.
        /// </summary>
        /// <param name="modalDialogService">The Modal Dialog Service</param>
        /// <param name="options">options that affect how the dialog behaves (can be null)</param>
        /// <returns>
        /// false if the user cancelled for form.
        /// true if the user completed the form (including any validation)
        /// The values the user entered are in the <see cref="Fields"/> that were created with the AddXXField methods
        /// </returns>
        public async Task <bool> ShowAsync(IModalDialogService modalDialogService, ModalDialogOptions options = null)
        {
            if (modalDialogService == null)
            {
                throw new ArgumentNullException(nameof(modalDialogService));
            }
            ModalDialogParameters mParams = new ModalDialogParameters();

            mParams.Add("Form", this);

            var result = await modalDialogService.ShowDialogAsync <Components.DataInputForm>(this.Title, options, mParams);

            return(result.Success);
        }
        public async Task <MessageBoxDialogResult> ShowMessageBoxAsync(string title, string message, MessageBoxButtons buttons, MessageBoxDefaultButton defaultButton)
        {
            if (buttons == MessageBoxButtons.OK && defaultButton != MessageBoxDefaultButton.Button1)
            {
                throw new ArgumentException("Must be Button 1", nameof(defaultButton));
            }
            if ((buttons == MessageBoxButtons.OKCancel || buttons == MessageBoxButtons.RetryCancel || buttons == MessageBoxButtons.YesNo) && defaultButton == MessageBoxDefaultButton.Button3)
            {
                throw new ArgumentException("Must be Button 1 or 2", nameof(defaultButton));
            }

            ModalDialogOptions options = new ModalDialogOptions();

            if (buttons == MessageBoxButtons.YesNo || buttons == MessageBoxButtons.AbortRetryIgnore)
            {
                options.ShowCloseButton        = false;
                options.BackgroundClickToClose = false;
            }

            ModalDialogParameters parameters = new ModalDialogParameters();

            parameters.Set("MessageBoxText", message);
            parameters.Set("MessageBoxButtons", buttons);
            parameters.Set("MessageBoxDefaultButton", defaultButton);

            ModalDialogResult result = await ShowDialogAsync <Blazor.ModalDialog.Components.MessageBoxForm>(title, options, parameters);

            if (result.Success == false)
            {
                Debug.Assert(buttons != MessageBoxButtons.YesNo && buttons != MessageBoxButtons.AbortRetryIgnore, "Should not be able dismiss message boxes with no cancel (except OK)");

                if (buttons == MessageBoxButtons.OK)
                {
                    return(MessageBoxDialogResult.OK);
                }
                else
                {
                    return(MessageBoxDialogResult.Cancel);
                }
            }
            else
            {
                return(result.ReturnParameters.Get <MessageBoxDialogResult>("MessageBoxDialogResult"));
            }
        }
        public Task <ModalDialogResult> ShowDialogAsync(Type dialogComponentType, string title, ModalDialogOptions options, ModalDialogParameters parameters)
        {
            if (!typeof(ComponentBase).IsAssignableFrom(dialogComponentType))
            {
                throw new ArgumentException($"{dialogComponentType.FullName} must be a Blazor Component");
            }

            parameters = parameters ?? new ModalDialogParameters();
            options    = options ?? new ModalDialogOptions();

            ModalDialogModel newDialogWindow = new ModalDialogModel(dialogComponentType, title, parameters, options);

            _dialogs.Push(newDialogWindow);

            OnChanged();

            return(newDialogWindow.Task);
        }
 public Task <ModalDialogResult> ShowDialogAsync <TBlazorComponent>(string title, ModalDialogOptions options, ModalDialogParameters parameters)
     where TBlazorComponent : ComponentBase
 {
     return(ShowDialogAsync(typeof(TBlazorComponent), title, options, parameters));
 }
 internal ModalDialogResult(bool success, ModalDialogParameters returnParameters)
 {
     this.Success          = success;
     this.ReturnParameters = returnParameters;
 }