c# - 如何订阅 Blazor.Radzen DialogService onClose 事件
问题描述
我正在使用blazor.radzen中非常有用的对话框。在我为模型创建的服务 (ModelService) 中,我有一个取消函数,它可以回滚对模型所做的任何更改。这可以使用对话框内的按钮触发,如下所示:
<RadzenButton ButtonStyle="ButtonStyle.Light" Icon="cancel" Text="Cancel" Click="@(args => Cancel(CurrentItem))" />
但是我需要在对话框关闭时触发此功能,以便取消对模型所做的更改。
DialogService(Radzen) 确实提供了 OnClose 事件。它似乎是这样声明的:
public event Action<dynamic> OnClose;
在 Visual Studio 中闲逛,我在 Dialog Service 的元数据中发现了这一点
public class DialogService : IDisposable
{
protected List<TaskCompletionSource<dynamic>> tasks;
protected List<object> dialogs;
public DialogService(NavigationManager uriHelper);
public event Action<dynamic> OnClose;
public event Action OnRefresh;
public event Action<string, Type, Dictionary<string, object>, DialogOptions> OnOpen;
public void Close(dynamic result = null);
[AsyncStateMachine(typeof(<Confirm>d__25))]
public Task<bool?> Confirm(string message = "Confirm?", string title = "Confirm", ConfirmOptions options = null);
public void Dispose();
public void Open<T>(string title, Dictionary<string, object> parameters = null, DialogOptions options = null) where T : ComponentBase;
public void Open(string title, RenderFragment<DialogService> childContent, DialogOptions options = null);
public Task<dynamic> OpenAsync<T>(string title, Dictionary<string, object> parameters = null, DialogOptions options = null) where T : ComponentBase;
public Task<dynamic> OpenAsync(string title, RenderFragment<DialogService> childContent, DialogOptions options = null);
public void Refresh();
}
我找不到处理程序的签名,所以我不知道如何订阅该事件。我也想知道订阅活动的最佳地点在哪里。我应该在 OnInitialized 上做吗?
解决方案
[Inject]
protected DialogService dialogService { get; set; }
protected override void OnInitialized()
{
dialogService.OnOpen += Open;
dialogService.OnClose += Close;
}
private void Close(dynamic obj)
{
//throw new NotImplementedException();
}
private void Open(string arg1, Type arg2, Dictionary<string, object> arg3, DialogOptions arg4)
{
//throw new NotImplementedException();
}
推荐阅读
- jmeter - 使用 Jmeter 进行性能测试 - 根据要求调整脚本
- qt - 使用 Popup 投射阴影
- php - 检查是否只有一个变量大于 PHP 中的另一个变量
- angular - Angular Pipe 和 TypeScript 类型保护
- c# - 将导出的 CngKey 导入 RSA 并再次导出
- java - 所有项目的 maven 依赖关系直方图(使用频率如何)
- python - Python:rdkit 库缺少许多功能
- python - 我如何使用 Selenium Python 遍历每个谷歌搜索页面,但它没有发生
- jhipster - 将 JHipster 实体子生成器集成到现有项目中
- python - Django - 获取登录用户组的列表。没有数据或“无法将关键字‘组’解析到字段中。选项有:id、名称、权限、用户”