示例#1
0
        public async Task <bool?> ShowMessageBox(MessageBoxOptions mboxOptions, DialogOptions options = null)
        {
            var parameters = new DialogParameters()
            {
                [nameof(MessageBoxOptions.Title)]      = mboxOptions.Title,
                [nameof(MessageBoxOptions.Message)]    = mboxOptions.Message,
                [nameof(MessageBoxOptions.CancelText)] = mboxOptions.CancelText,
                [nameof(MessageBoxOptions.NoText)]     = mboxOptions.NoText,
                [nameof(MessageBoxOptions.YesText)]    = mboxOptions.YesText,
            };
            var reference = Show <MudMessageBox>(parameters: parameters, options: options, title: mboxOptions.Title);
            var result    = await reference.Result;

            if (result.Cancelled || !(result.Data is bool))
            {
                return(null);
            }
            return((bool)result.Data);
        }
示例#2
0
        public IDialogReference Show(Type contentComponent, string title, DialogParameters parameters, DialogOptions options)
        {
            if (!typeof(ComponentBase).IsAssignableFrom(contentComponent))
            {
                throw new ArgumentException($"{contentComponent.FullName} must be a Blazor Component");
            }
            var dialogReference = CreateReference();

            var dialogContent = new RenderFragment(builder =>
            {
                var i = 0;
                builder.OpenComponent(i++, contentComponent);

                if (!dialogReference.AreParametersRendered)
                {
                    foreach (var parameter in parameters)
                    {
                        builder.AddAttribute(i++, parameter.Key, parameter.Value);
                    }

                    dialogReference.AreParametersRendered = true;
                }
                else
                {
                    i += parameters.Count;
                }

                builder.AddComponentReferenceCapture(i++, inst => { dialogReference.InjectDialog(inst); });
                builder.CloseComponent();
            });
            var dialogInstance = new RenderFragment(builder =>
            {
                builder.OpenComponent <MudDialogInstance>(0);
                builder.SetKey(dialogReference.Id);
                builder.AddAttribute(1, "Options", options);
                builder.AddAttribute(2, "Title", title);
                builder.AddAttribute(3, "Content", dialogContent);
                builder.AddAttribute(4, "Id", dialogReference.Id);
                builder.CloseComponent();
            });

            dialogReference.InjectRenderFragment(dialogInstance);
            OnDialogInstanceAdded?.Invoke(dialogReference);

            return(dialogReference);
        }
示例#3
0
 public IDialogReference Show(Type contentComponent, string title, DialogOptions options)
 {
     return(Show(contentComponent, title, new DialogParameters(), options));
 }
示例#4
0
 public IDialogReference Show <T>(string title, DialogParameters parameters, DialogOptions options) where T : ComponentBase
 {
     return(Show(typeof(T), title, parameters, options));
 }
示例#5
0
 public IDialogReference Show <T>(string title, DialogOptions options) where T : ComponentBase
 {
     return(Show <T>(title, new DialogParameters(), options));
 }
示例#6
0
 public Task <bool?> ShowMessageBox(string title, string message, string yesText = "OK",
                                    string noText = null, string cancelText = null, DialogOptions options = null)
 {
     return(this.ShowMessageBox(new MessageBoxOptions
     {
         Title = title,
         Message = message,
         YesText = yesText,
         NoText = noText,
         CancelText = cancelText,
     }, options));
 }
示例#7
0
        public IDialogReference Show(Type contentComponent, string title, DialogParameters parameters, DialogOptions options)
        {
            if (!typeof(ComponentBase).IsAssignableFrom(contentComponent))
            {
                throw new ArgumentException($"{contentComponent.FullName} must be a Blazor Component");
            }
            var             dialogInstanceId = Guid.NewGuid();
            DialogReference dialogReference  = null;
            var             dialogContent    = new RenderFragment(builder =>
            {
                var i = 0;
                builder.OpenComponent(i++, contentComponent);
                foreach (var parameter in parameters._parameters)
                {
                    builder.AddAttribute(i++, parameter.Key, parameter.Value);
                }
                builder.CloseComponent();
            });
            var dialogInstance = new RenderFragment(builder =>
            {
                builder.OpenComponent <MudDialogInstance>(0);
                builder.AddAttribute(1, "Options", options);
                builder.AddAttribute(2, "Title", title);
                builder.AddAttribute(3, "Content", dialogContent);
                builder.AddAttribute(4, "Id", dialogInstanceId);
                builder.CloseComponent();
            });

            dialogReference = new DialogReference(dialogInstanceId, dialogInstance, this);

            OnDialogInstanceAdded?.Invoke(dialogReference);

            return(dialogReference);
        }
示例#8
0
 public void SetOptions(DialogOptions options)
 {
     Options = options;
     ConfigureInstance();
     StateHasChanged();
 }