public async Task Close_Ok() { var cut = Context.RenderComponent <Toast>(); var service = Context.Services.GetRequiredService <ToastService>(); var option = new ToastOption() { ChildContent = new RenderFragment(builder => { builder.AddContent(0, "Toast ChildContent"); }) }; await service.Show(option); await option.Close(); }
private async Task DownloadAsync(IEnumerable <Foo> items) { // 构造弹窗配置信息,进行弹窗操作 var cate = ToastCategory.Information; var title = "自定义下载示例"; var content = "请先选择数据,然后点击下载按钮"; if (items.Any()) { cate = ToastCategory.Success; content = $"开始打包选中的 {items.Count()} 条数据,完成后自动关闭本窗口"; } var option = new ToastOption() { Category = cate, Title = title, Content = content, }; // 弹出 Toast await ToastService.Show(option); // 如果已选择下载项进行打包下载操作 if (items.Any()) { // 禁止自动关闭 option.IsAutoHide = false; // 开启后台进程进行数据处理 // 传递 Option 过去是为了异步操作结束后可以关闭弹窗 await MockDownLoadAsync(); // 关闭 option 相关联的弹窗 await option.Close(); // 弹窗告知下载完毕 await ToastService.Show(new ToastOption() { Category = ToastCategory.Success, Title = "自定义下载示例", Content = "数据下载完毕", }); } }