Skip to content

DOM API Bindings and Blazor support #28820

Open
@marinasundstrom

Description

@marinasundstrom

This probably falls under runtime but I think it is relevant to the Web framework.

There is a project in the Mono repository for generating bindings to the DOM API through JavaScript interop.
The plan/idea is to generate the C# code bindings from TypeScript. But it seems like the effort is on hold.

See: mono/mono#10775

However: I see an opportunity in combining that effort with Blazor, enabling developers to use these classes directly from Razor. (Just for Blazor Web, of course)

Instead of an ElementReference you could cast a random HTML element into its corresponding class to perform stuff you otherwise would need manually write JavaScript (if there is not a third-party library for that)

We need this functionality in order to build powerful web apps with just C#.

I have not thought about the server-side scenario, but I guess that you could trigger JavaScript in the browser similar to today.

<canvas @ref="myCanvas" height="200" width="200" />

@code 
{
    Canvas myCanvas;
    Canvas2DContext context;

    protected async Task OnAfterRenderAsync(bool firstRender) 
    {
       if(!firstRender) 
       {
            if(context == null) 
            {
                context = await myCanvas.GetContextAsync("2d");
            }
            var image = new Img();
            image.Href = "/foo.png";
            await context.DrawImageAsync(image, 25, 25);
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    affected-fewThis issue impacts only small number of customersarea-blazorIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing onefeature-blazor-jsinteropThis issue is related to JSInterop in Blazornot-on-roadmapseverity-majorThis label is used by an internal tool

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions