Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Blazor: Using EventCallback with CascadingValue/CascadingParameter - is that possible?

$
0
0

I have a blazor application and I want to use EventCallback in my grandchild to call a function in my grandparent. The problem is, that the method in my grandparent never gets called.

I also use "normal" parameters to communicate from parent to child and in this case EventCallBack is working fine.

But doing it like this, it doesn't work:

This is the grandparent:

@page "/counter"@rendermode InteractiveServer<PageTitle>Counter</PageTitle><h1>Counter</h1><p role="status">Current count: @currentCount</p><CascadingValue Value="IncrementCount" Name="SetCount"><Child/></CascadingValue>@code {    private int currentCount = 0;    private void IncrementCount()    {        currentCount++;    }}

This is the child:

<h3>Child</h3><p>I'm only existing to demonstrate something...'</p><Grandchild/>@code {}

And this the grandchild:

<h3>Grandchild</h3><button class="btn btn-primary" @onclick="HandleOnClick">Click me</button>@code {    [CascadingParameter(Name = "SetCount")]    public EventCallback SetCount { get; set; }    private void HandleOnClick()    {        SetCount.InvokeAsync();    }}

Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>