Maui Blazor 中文社区 QQ群:645660665

Bootstrap Blazor 实战 Dialog 对话框组件快速入门

官方文档

1. 注入服务 DialogService

@inject DialogService DialogService

或者后置代码

[Inject]
[NotNull]
private DialogService? DialogService { get; set; }

2. 弹出说明

await DialogService.Show(new DialogOption()
{
    Title = "运行结果",
    IsScrolling = true,
    IsCentered = true,
    BodyTemplate = new RenderFragment(builder =>
    {
        builder.OpenElement(1, "p");
        builder.AddContent(2, "结果1结果2结果3结果4");
        builder.CloseElement();
    })
});

image

[特别介绍] SweetAlert 弹窗组件

SweetAlert

[Inject]
[NotNull]
private SwalService? SwalService { get; set; }

var op = new SwalOption()
{
    Title = Localizer["SwalOptionTitle"],
    Content = Localizer["SwalOptionContent"]
};
var ret = await SwalService.ShowModal(op);

image

3. 弹出组件

DialogService.Show(new DialogOption()
{
    Title = "Built-in Counter component",
    Component = BootstrapDynamicComponent.CreateComponent<Counter>()
});

image

4. 弹出编辑框

    string CurrentDirectory = "";
    void LoadFiles() { }
    public class NewFolders
    {

        [DisplayName("文件夹名称")]
        public string NewFolderName { get; set; }

    }


    private async Task ShowNewFolderDialog()
    {
        var newFolders = new NewFolders();
        var option = new EditDialogOption<NewFolders>()
        {
            Title = "新文件夹名称",
            Model = newFolders,

            OnEditAsync = context =>
            {
                string path = Path.Combine(CurrentDirectory, newFolders.NewFolderName);

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                    LoadFiles();
                }

                return Task.FromResult(true);
            }
        };

        await DialogService.ShowEditDialog(option);
    }

image

posted @   AlexChow  阅读(1399)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· 易语言 —— 开山篇
点击右上角即可分享
微信分享提示