I do not seem to be able to supply a callback from the parent component to the child, when teh child is rnedered using @Body
:
<CascadingValue Value="isGB">
<CascadingValue Value="HandleChange">
@Body
</CascadingValue>
</CascadingValue>
</div>
@code {
private void HandleChange(bool isgb)
{
throw new Exception();
isGB = isgb;
StateHasChanged();
}
}
What I ave in the child component:
[CascadingParameter]
public EventCallback<bool> HandleChange { get; set; }
private async Task ChangeIsGB(bool isgb)
{
IsGB = isgb;
await HandleChange.InvokeAsync(isgb);
}
But the event does not fire, sadly enough. Why?
2
Answers
Actually, setting the rendermode in App.razor solved teh issue. I read that without this events would not fire. (Not even click events)
This is it:
This essentially sets the rendermode to interactiev server by default. Otherwise teh default rendermode is static.
You can’t pass the method directly as a
CascadingValue
the way you’re trying, but what you can do is create anEventCallback
and pass that instead.Hosting Page (MainLayout.razor?):