Set EventCallback outside of a Blazor component?

Turns out you can assign an event callback from C# code like this:

this.ProgressManager.UpdateNotification = new EventCallback(this, (Action)Refresh);

void Refresh() {}

It also works with async methods, e.g.:

this.ProgressManager.UpdateNotification = new EventCallback(this, (Func<ValueTask>)RefreshAsync);

ValueTask RefreshAsync() {}

UPDATE

You can also use EventCallbackFactory to more conveniently create event callback objects, e.g.:

new EventCallbackFactory().Create(this, Refresh)

Leave a Comment