Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using SVGS in blazor page

Tags:

razor

blazor

I have a razor component and I want to add an SVG to it.

Would It be best to create a component for each SVG so that I can re-use it pretty easily or would it be better to just include the SVG into the blazor page?

Those are just the two ways I thought that it could be done, whats the best way to go about this and how can I implement it?

Haven't found any rescources, so I wasn't able to try anything.

like image 523
spindi598 Avatar asked Dec 18 '22 13:12

spindi598


1 Answers

I gave it try, as far as I can see the Blazor Component model works perfectly well with Svg:

SvgHolder.razor

<svg width="100" height="100">
   @ChildContent
</svg>

@code {
    [Parameter]
    public RenderFragment ChildContent { get; set; }

}

SvgSample.razor

<circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />

@code {

}

TestPage.razor

<SvgHolder >
    <SvgSample />
</SvgHolder>
like image 131
Henk Holterman Avatar answered Apr 28 '23 22:04

Henk Holterman