aspnetcore
aspnetcore copied to clipboard
Parent-Childs hierarchy
The idea is, I want to build the hierarchy after rendering. The component will know and easy to access its parent and child component by using Parent and Childrens property.
Is there a way to achieve this?
I have a work-around, hope this helps someone try to address some issue.
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
if (CSHTMLHelper.PARENT == null)
{
CSHTMLHelper.PARENT = this;
}
Parent = CSHTMLHelper.PARENT;
CSHTMLHelper.PARENT = this;
if (Parent != null
&& Parent != this)
{
Parent.Childrens.Add(this);
}
base.BuildRenderTree(builder);
CSHTMLHelper.PARENT = Parent;
}