Please refer the following code blocks. For that code blocks, I have tried to access the parent component values into child component, but it always return the null value in child component.
<Parent TValue="TreeData">
<Child TValue="TreeNode<TreeData>"></Child>
</Parent>
@code {
public class TreeData
{
public string Value { get; set; }
}
public class TreeNode<TreeData>
{
public int Count { get; set; }
}
}
**Parent Component:**
<CascadingValue Value="@this">
@ChildContent
</CascadingValue>
**Child Component:**
@code {
[CascadingParameter]
private Parent<TValue> ParentObj { get; set; }
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
//Parent obj always returns the null value
ParentObj?.UpdateChildProperties("UpdateData", this);
}
}