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();
})
});

[特别介绍] SweetAlert 弹窗组件
[Inject]
[NotNull]
private SwalService? SwalService { get; set; }
var op = new SwalOption()
{
Title = Localizer["SwalOptionTitle"],
Content = Localizer["SwalOptionContent"]
};
var ret = await SwalService.ShowModal(op);

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

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);
}

关联项目
FreeSql QQ群:4336577
BA & Blazor QQ群:795206915
Maui Blazor 中文社区 QQ群:645660665
知识共享许可协议
本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可。欢迎转载、使用、重新发布,但务必保留文章署名AlexChow(包含链接: https://github.com/densen2014 ),不得用于商业目的,基于本文修改后的作品务必以相同的许可发布。如有任何疑问,请与我联系 。
转载声明
本文来自博客园,作者:周创琳 AlexChow,转载请注明原文链接:https://www.cnblogs.com/densen2014/p/16995443.html
AlexChow
今日头条 | 博客园 | 知乎 | Gitee | GitHub


浙公网安备 33010602011771号