BlazorExtensions / Canvas

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

Unable to change the stroke color per rect. #129

Closed thedead closed 1 year ago

thedead commented 1 year ago

Hi All,

When setting the StrokeStyle, I can't change the color per rect, they all end up the same color. When I did this in straight javascript it worked fine. What do I need to do differently in blazor to allow me to change the stroke color per rect?

`

@code { private Canvas2DContext _context;

protected BECanvasComponent _canvasNet;

private int objHeight = 10;
private int objWidth = 30;

protected override async Task OnAfterRenderAsync(bool firstRender)
{
    this._context = await this._canvasNet.CreateCanvas2DAsync();

    await this._context.SetStrokeStyleAsync("green");
    await this._context.RectAsync(4, 4, objWidth, objHeight);

    await this._context.SetStrokeStyleAsync("red");
    await this._context.RectAsync(54, 54, objWidth, objHeight);

    await this._context.RectAsync(154, 154, objWidth, objHeight);

    await this._context.StrokeAsync();

}

}`