BlazorExtensions / Canvas

HTML5 Canvas API implementation for Microsoft Blazor
MIT License
602 stars 145 forks source link

This is not for WebAssembly #139

Open GoshenJimenez opened 3 weeks ago

GoshenJimenez commented 3 weeks ago

I realize that this component is not working in WASM or at least I have not been able to make it work (out of the box) from a WASM Project. The OnAfterRenderAsync method is not called from WASM. It works on Blazor Server but not for WASM as far as I know. Please feel free to correct me and or show me how to get it working on WASM if I am wrong.

@using Blazor.Extensions.Canvas.Canvas2D;
@using Blazor.Extensions.Canvas
@using Blazor.Extensions;

<BECanvas Width="300" Height="400" @ref="_bgCanvas" ></BECanvas>

@code {
    private Canvas2DContext? _bgContext;
    protected BECanvasComponent? _bgCanvas;

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        this._bgContext = await this._bgCanvas.CreateCanvas2DAsync();
        await this._bgContext.SetFillStyleAsync("green");

        await this._bgContext.FillRectAsync(10, 100, 100, 100);

        await this._bgContext.SetFontAsync("48px serif");
        await this._bgContext.StrokeTextAsync("Hello Blazor!!!", 10, 100);
    }
}