Blazor: Problem with EventCallBack in Generic component
See original GitHub issueDescribe the bug
My event is not called in the parent component when using EventCallBack in a child component. I’ve already been through #12116 and #8385 but It still not working
To Reproduce
My code: Tree.razor (child)
@typeparam TNode
<HTML WITH DOUBLECLICK EVENT>
@code{
[Parameter] public EventCallback<DoubleClickVariableEventArgs> OnDoubleClickOnVariable { get; set; }
private void OnDoubleClickTree(object sender, MouseEventArgs e)
{
Console.WriteLine("TEST");
OnDoubleClickOnVariable.InvokeAsync(new DoubleClickVariableEventArgs(selectedNode.Path, selectedNode.IsReadOnly));}
}
“TEST” is correctly displayed in the console. so the problem is from InvokeAsync.
My eventargs:
public class DoubleClickVariableEventArgs : EventArgs
{
public DoubleClickVariableEventArgs(string path ,bool isReadOnly)
{
Path = path;
IsReadOnly = isReadOnly;
}
public string Path { get; private set; }
public bool IsReadOnly { get; private set; }
}
MAIN.razor (parent)
<Tree TNode="TreeItem" Nodes="Items" ChildSelector="@(item => item.Childs)" @bind-SelectedNode="selectedNode" @bind-ExpandedNodes="ExpandedNodes" HasChildNodes="@(item => item.Childs?.Any() == true)" OnDoubleClickOnVariable="OnVariableDoubleClick">
<TitleTemplate>@context.Text</TitleTemplate>
</Tree>
@code{
private async Task OnVariableDoubleClick(DoubleClickVariableEventArgs e)
{
Console.WriteLine("TEST2");
}
}
I tried some of the solutions like writing the type : TNode = "TreeItem"
or writing OnDoubleClickOnVariable="(DoubleClickVariableEventArgs x) => OnVariableDoubleClick(x)"
Without success…
I want to say that I used the exact same structure in another non-generic component and it’s working perfectly.
Further technical details
Lastest Blazor, VS Preview versions
P.S. On of my first post on github sorry if it’s unreadable
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5 (4 by maintainers)
Top Results From Across the Web
EventCallback<TValue> with a Generic Component ...
Describe the bug If a Blazor Component has multiple Generic Parameters then EventCallbacks cannot be bound without an intermediary class.
Read more >Blazor generic component with eventcallback
It is working and the parent component can bind to the value and gets the updates. ... if (_Value == value) return;. was...
Read more >Generic Args to Blazor EventCallback not recognised
The @OnClick in the component instantiation gets a red squiggle and a "Can't Resolve Method..." popup. This code compiles correctly. Activity settings.
Read more >Component events
EventCallback <T> typically calls back a method with the signature private Task SomeName(T value) - where the exposure level of the method is...
Read more >Blazor Component Callback from a RenderFragment ...
This article covers the problem and solution to enable Blazor Components to allow callbacks, with optional data, from an external template.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m having the same issue…
@Flearz thanks for contacting us.
@rynowak can you take a look at this and see if there’s an issue?