N
N
NewDevLab2020-11-26 16:20:52
C++ / C#
NewDevLab, 2020-11-26 16:20:52

How to subscribe to an event?

Hitch with syntax in +=

public interface IContentState {
  public EventCallback<IContentState> OnStateChanged { get; set; }
}

public class Parent : IContentState {
  public EventCallback<IContentState> OnStateChanged { get; set; }
  private async Task StateChangedInvoke() {	
    await OnStateChanged.InvokeAsync(this);
  }
}
public class Child() {
  public void RegisterContent(IContentState contentState) {
    ContentState.OnStateChanged += OnContentStateChanged;
  }	
  protected void OnContentStateChanged(IContentState contentState) {
    // do
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2020-11-26
@vabka

You do not have an event in IContentState, but just a delegate.
Try to write

public event EventCallback<IContentState> StateChanged;

PS: it is customary to call events without the prefix On

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question