dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.5k stars 10.04k forks source link

Blazor Custom EventHandler #32100

Closed Julien-Marpault closed 3 years ago

Julien-Marpault commented 3 years ago

.Net 5.0 / Blazor WSAM / SDK 5.0.202 x64

I made a tooltip component with Blazor WASM. it requires event not supported with Blazor.

So I declared custom event handlers:

[EventHandler("onmouseenter", typeof(EventArgs), true, true)]
[EventHandler("onmouseleave", typeof(EventArgs), true, true)]
public static class EventHandlers
{
}

It works fine but things getting harder when making an RCL.

if custom events aren't in the RCL the RCL doesn't work properly. but if event are declared in RCL and in the main project it doesn't work too, there is an error for duplicate declaration. Is it possible to bypass the double event declaration, or isolate it to their respective project or making RCL using event declaration from the project?

Thanks.

javiercn commented 3 years ago

@JulienM28 thanks for contacting us.

I believe we explicitly don't support overriding custom events. You can "override" this event by creating your alternative custom event that targets the same original DOM event.

Julien-Marpault commented 3 years ago

This solution is only possible with .Net 6 with the new custom event register function ?

javiercn commented 3 years ago

Yep, this requires 6.0