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

Iterating through ChildContent in Blazor

$
0
0

I'm trying to achieve something like this using Blazor and MudBlazor:

MainPage.razor

<Section><MudTextField ... /><MudTimePicker ... /><MudNumericField ... /></Section>

Section.razor

@for (int i = 0; i < Children.Count; i += 2){<div style="width:50%">        @Children[i]</div>    @if (i + 1 < Children.Count)    {<div style="width:50%">            @Children[i + 1]</div>    }}@code{    [Parameter]    public required RenderFragment ChildContent { get; set; }    private List<RenderFragment> Children = new();    private void ProcessChildContent()    {        // some transformation to get all children and be able to iterate through them        // any other idea is also good as long as HTML stays like above    }}

Is something like this even possible in Blazor?

I tried already iterating through frames using RenderTreeBuilder but failed. I don't know if this is the right approach. Using different props for each child won't do, because I'd like to pass unknown amount of children. I tried also this twice but once I got error because of lacking ChildContent Prop and another time all children were re-rendered each time browser window was dragged, resized or any input changed. HashSet instead of List seemed to solve it but overall it doesn't look like the right approach to me.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



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