Hi
do you know if it s possible to add Radzen element in a RazenStack using only C# ?
if yes how?
thank you for your help
Hi
do you know if it s possible to add Radzen element in a RazenStack using only C# ?
if yes how?
thank you for your help
Hi @Tia,
Adding Blazor components to other Blazor components via C# is generally done via creating RenderFragment. More info is available in the Blazor documentation: ASP.NET Core Blazor advanced scenarios (render tree construction) | Microsoft Learn
thank you for your response but i think i make something wrong because i can make it working
here my very simple code for example, do you know what i make wrong?
I have no error but just the stack didn t display
private RenderFragment? _ToolBarRender { get; set; }
protected async override Task OnInitializedAsync()
{
_ToolBarRender = CreateComponent();
}
private RenderFragment CreateComponent() => builder =>
{
builder.OpenComponent(0, typeof(RadzenStack));
builder.AddAttribute(1, "Stack", new RadzenStack() {Visible=true});
builder.AddAttribute(2, "Button", new RadzenButton() { Text = "Test", Visible=true});
builder.CloseComponent();
};
What you have done wrong is using AddAttribute for components. This won’t work.
Here is some sample code that shows a working implementation radzen-blazor/Radzen.Blazor/Markdown/BlazorMarkdownRenderer.cs at 91676d802c824b0ea9744a417d2219f3d91973ab · radzenhq/radzen-blazor · GitHub
Note how components attributes are set and how child content is added.
Hi,
i have udpate the code to put each button in a compenent something like that
but it display only one button
any idea?
RenderFragment Button1 = new RenderFragment(headerBuilder =>
{
headerBuilder.OpenComponent<RadzenButton>(0);
headerBuilder.AddAttribute(1, nameof(RadzenButton.Text), "Button1");
headerBuilder.CloseComponent();
});
RenderFragment Button2 = new RenderFragment(headerBuilder =>
{
headerBuilder.OpenComponent<RadzenButton>(0);
headerBuilder.AddAttribute(1, nameof(RadzenButton.Text), "Button2");
headerBuilder.CloseComponent();
});
builder.OpenComponent<RadzenStack>(0);
builder.AddAttribute(1, nameof(RadzenStack.ChildContent), Button1);
builder.AddAttribute(2, nameof(RadzenStack.ChildContent), Button2);
builder.CloseComponent();
You cannot set the same attribute twice. Add the buttons in the same render fragment.