question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Blazor: Problem with EventCallBack in Generic component

See original GitHub issue

Describe 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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
partyelitecommented, Dec 18, 2019

I’m having the same issue…

1reaction
javiercncommented, Nov 29, 2019

@Flearz thanks for contacting us.

@rynowak can you take a look at this and see if there’s an issue?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found