Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

How to access a method of a dynamic component?

$
0
0

I have a number of components that implement an interface, for example:

@implements MyInterface@code {    public void MyMethod() { }}

On my page, I add these components dynamically using a ComponentMetadata class, for example:

private class ComponentMetadata{    public Type Type { get; set; }    public IDictionary<string, object> Parameters { get; set; }    public ComponentMetadata(Type type)    {        this.Type = type;    }}

And added as follows:

@{    var c = components.Single(x => x.Type == typeof(MyComponent));}<DynamicComponent Type="@c.Type" Parameters="@c.Parameters" />

Everything works as expected.

Now I would like to call MyMethod on each dynamic component that implements the interface. Is this possible, and if yes, how can I achieve this?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>