Forum Discussion
DaveDigisynth
May 03, 2024Copper Contributor
Blazor .Net 8 : Get a referenece to the actual instance of a child component
Given the following markup:
<Wizard Title="Add workplace" OnSave="PersistWizardData">
<WizardStep Title="Checklist">
<AddWorkplaceWizardStepChecklist />
</WizardStep>
<WizardStep Title="Locate workplace">
<AddWorkplaceWizardStepLocateWorkplace />
</WizardStep>
<WizardStep Title="Workplace details">
<AddWorkplaceWizardStepChecklist />
</WizardStep>
<WizardStep Title="Amenities">
<AddWorkplaceWizardStepLocateWorkplace />
</WizardStep>
<WizardStep Title="Photos">
<AddWorkplaceWizardStepChecklist />
</WizardStep>
<WizardStep Title="Access hours">
<AddWorkplaceWizardStepLocateWorkplace />
</WizardStep>
<WizardStep Title="Contact details">
<AddWorkplaceWizardStepChecklist />
</WizardStep>
</Wizard>
The Wizard component maintains a collection of WizardSteps. As I navigate from one step to another I want to call a method on the underlying component (e.g. AddWorkplaceWizardStepChecklist).
From my WizardStep component is it possible to get a reference to the underlying instance of the rendered child so I that can directly call methods on it?
- DaveDigisynthCopper Contributor
Found a solution. Adding @ref to bind the dynamic component to a property in the code behind allows me to access the Instance property to get to the underlying type.