Reputation: 21
How do you pass a reference to the parent RenderingFragment to the child component/content when creating a razor component in c# (NOT using .razor) ComponentBase overloading the protected override void BuildRenderTree(RenderTreeBuilder builder) seems not to work as expected.
Upvotes: 1
Views: 702
Reputation: 107
I had the same question when i wanted to cascade a component to its child components. Solved it as shown below:
builder.OpenComponent<CascadingValue<TValue>>(0);
builder.AddAttribute(1, "Value", this);
builder.AddAttribute(2, "ChildContent", (RenderFragment)((builder2) => {
builder2.AddContent(3, ChildContent);
}));
builder.CloseComponent();
Good luck!
Upvotes: 4