I would like to know how I can implement the @ref
attribute using the RenderTreeBuilder
.
Following blazor code is a minimalistic example to discuss about a solution:
<MudForm @ref="_Form">@ChildContent</MudForm>
@code {
[Parameter]
public RenderFragment ChildContent { get; set; }
private MudForm _Form;
}
I would like to reimplement the blazor code referring to the MudForm
using the RenderTreeBuilder
. Therefore I already tried the following approach but it didn't work for me:
private RenderFragment formControl => (builder) =>
{
builder.OpenComponent<MudForm>(0);
builder.AddElementReferenceCapture(1, (value) => { _Form = value.Context; });
builder.AddAttribute(2, nameof(MudForm.ChildContent), ChildContent);
builder.CloseComponent();
};
I don't know if the AddElementReferenceCapture
-method is correct to bind _Form
to the components instance using the RenderTreeBuilder
. Could someone please help me with this?
RenderTreeBuilder
builder.AddComponentReferenceCapture(6, (value) => { _Form = value as MudForm; });
and this worked for me – Claret