Using EventCallback parameters
An event callback is a method that is passed to another method when a particular event occurs. For example, when the button on the Alert
component is clicked, the @onclick
event uses the OnOk
parameter to determine the method that should be called. The method that the OnOK
parameter references is defined in the parent component.
As previously stated, EventCallback
parameters are used to share information from the child component to the parent component. They share information with their parent and notify their parent when something, such as a button click, has occurred. The parent component simply specifies the method to call when the event is triggered.
This is an example of an EventCallback
parameter:
[Parameter] public EventCallback OnOk { get; set; }
The following example uses a lambda expression for the OnOk
method. When the OnOk
method is called, the value of the showAlert
property is set to false:
<Alert Show="showAlert" OnOk="...