如何订阅 Blazor.Radzen DialogService onClose 事件

How to Subscribe to the Blazor.Radzen DialogService onClose event

我正在使用非常有用的 dialog from 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 我在对话服务的元数据中找到了这个

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