Skip to content

Blazor - ability to insert a component dynamically and have it draw itself #18709

@LaughingJohn

Description

@LaughingJohn

One frustration I have had is in the use of RenderFragment. This is related to the polymorphic lists you are looking at.

What I wanted to be able to do is have component at the very top level (app) which can render other components (in my case dialogs). I've found this very cumbersome to achieve.

My aim was to be able to replicate MessageBox as per WPF/Winforms/Silverlight (and other shared dialogs) and be able to create one in code and display it from any other component without having to add it to the markup of every component that uses it.

Ideally I want to have a parent component into which I can pass other child components which I have "newed up" and filled in the parameters in code. I then want the base component to be able to add that to its render tree and have the child component render itself (which it already knows how to do because of razor). Crucially I want the component in the render tree to be a reference to the one that I pass in and not a copy.

It's quite hard to explain what I've come up with for dialogs, but essentially I have to define a dialog, and then also create a method to render the dialog. I have a top level dialog manager and via a couple of service classes I pass in the Render method to get it to display the dialog. It's better than nothing but pretty naff.

I've attached my attempt at a solution - some of the complexity may be down to my misunderstanding, but any help gratefully received!

Thanks.
TestDialogManager.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions