Passing values to a MudBlazor Dialog

Sometimes you want to just pass values to a dialog, but other times, you want events in the dialog to trigger things before the dialog is actually closed.  Here's an example.

private async Task OpenFiltersDialog()
{
    var options = new DialogOptions
        {
            CloseOnEscapeKey = true,
            Position = DialogPosition.CenterLeft
        };

    var originalFiltersViewModel = AccountPickerState.AccountFiltersViewModel;
    var sub = AuthState.SubjectId;

    var dialogParameters = new DialogParameters<AccountFiltersDialog>();
    dialogParameters.Add(p => p.ViewModel, originalFiltersViewModel);
    dialogParameters.Add(p => p.IncludeSoftDeletedFilter, false);

    dialogParameters.Add(p => p.OnFiltersChanged, new EventCallbackFactory().Create<AccountFiltersViewModel>(this, UpdateAccountPickerState));

    var result = await DialogService.Show<AccountFiltersDialog>("Accounts filter", dialogParameters, options).Result;

    if (result.Canceled)
    {
        await _mediator.Send(new AccountPickerState.UpdateFilters { FiltersViewModel = originalFiltersViewModel });
    }
}

And here's the method we're passing in:

public async Task UpdateAccountPickerState(AccountFiltersViewModel filters)
{
    logger.LogInformation("Updating filter with {ViewModel}", filters);
    await _mediator.Send(new AccountPickerState.UpdateFilters { FiltersViewModel = filters });
    await _mediator.Send(new AccountPickerState.RefreshAccountSelectors());
}