I am learning Blazor. https://learn-blazor.com/
I am having some difficulty creating a component in C# by overriding the BuildRenderTree(RenderTreeBuilder builder) method of the BlazorComponent class.
Here is my class:
public class TestComponent : BlazorComponent
{
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
builder.OpenElement(1, "p");
builder.OpenElement(2, "strong");
builder.AddContent(3, "hello");
builder.CloseElement();
builder.CloseElement();
base.BuildRenderTree(builder); // With or without this line it doesn't work
}
}
I use it in my page like this:
<TestComponent></TestComponent>
I have tested it with and without that last line base.BuildRenderTree(builder); but either way it doesn't render. I've made the component childishly simple (just a paragraph tag, strong tag and one word of content) so I'm lost as to why it won't render. The code builds just fine.
Can anybody see what I did wrong please?
First off don't use that web site anymore. I've learned Blazor through that web site. It is an excellent web site, and the guy did a superb work. But alas, he stopped updating it, at least for the last six months. The materials have become old and useless. Right now, I'm not aware of any good substitution.
Try this:
Place base.BuildRenderTree(builder); at the start of the BuildRenderTree method , not at the end.
Use ComponentBase instead of BlazorComponent...
BlazorComponent is dead...
0 for the sequence parameter.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With