Can RadzenTabs `private List<RadzenTabsItem> tabs` have a public read accessor?

Hi there, this is my use-case:

My RadzenTabs has a dynamic amount of tabs and added during runtime based on conditions.

Based on user-actions I sometimes want to programmatically set the selected tab to a specific one. I'm doing that by updating the SelectedIndex (If there's a better way to do this, lemme know :slight_smile: )

So anyways, it's rather complicated to find the correct tab to select by index alone. RadzenTabs.Tabs (capitalized) is just returning a RenderFragment, so that seems kinda useless to access them programmatically, but RadzenTabs.tabs (lowercase) is returning the actual tab classes.

Through this property I'm able to determine by name in which index location a certain tab is, and change the selected index to the correct.

An alternative would be to have method that lets me set the selected tab index by title

Hi @RonSijm,

We don't want to make that collection public as people will try to add / remove items to it and expect the tabs to update (they won't). I would recommend to keep a separate collection of tab texts which would allow you to find a tab's index quickly.

Hi Korchev,

I have a similar issue, in my case I would like to customize the RadzenTabs and create a custom control. In order to do so, the "tabs" need to be public. Keeping a separate collection of tabs would mean double work in my case. Per your comment, I am sure people will always have expectations of how this would work, but managing these expectations might be an impossible job.

Why do you want access to that collection? What do you plan to do with it?

I have a derived class that extends the Radzetabs and I have a Tabitem that extends the Radzentabsitem. Each Tabitem has its own Templateform, upon initializing of the Tabs I already know if the templateform is valid or not. Upon changing of the tabs I do validate the TabItem. Hence I always have a validated state of a tabitem.

I would like to be able to loop the tabs(collection) to check if a tab is valid, and set focus and color if it is not valid before saving the page.

Hi @Mickey,

You can implement this in a similar way to how RadzenTabsItem works. Override OnInitialized and notify the parent that a tab has been added. We really don't want to make this collection public because of the issues I have already mentioned.

@korchev : Thanks! Works like a charm!

This is a bit of a necto post. I understand the reasons for not making tabs public.

Would it be possible though to expose:

  • RadzenTabs.IndexOf(RadzenTabsItem tab);

As a stretch, could these types of operations be added?

  • public RadzenTabsItem? GetTabItemByIndex(int index) => tabs.ElementAtOrDefault(index);
  • public int TabCount => tabs.Count

That way, if say we wanted to get a tab by index we could? If we needed to loop through the tabs, that could still be done via index?
Or rather than exposing tabs directly, we could get an IEnumerable of the tab items?

  • public IEnumerable<RadzenTabsItem> GetTabItems() => tabs.AsEnumerable(); // or tabs.AsReadOnly()

Hi @Peter_Godwin,

What are your requirements? Why do you need to find the index of a tab instance?

My use case was around setting a Query Parameter with a name/identifier of the tab so that changing tabs caused a navigation, and would allow for linking to a specific tab page.

Eg, RadzenTabs.Change, navigate to ?tab=mytab. I wanted to loop through the tab items to check which tab was β€œmytab” and then set it as the current tab.

I ended up doing something I guess similar to @Mickey : I created a new class that inherited from RadzenTab, added a TabItems property. I then created an inherited RadzenTabsItem class to override the OnInitialized to register the item into the TabItems property.

Unfortunately, I did find setting SelectedIndex from NavigationManager.LocationChanged would not actually change tabs, and I had to use reflection to call SelectTab instead. Eg Playground | Radzen Blazor Components

This page shows how to set the selected tab index from query string without using reflection: radzen-blazor/RadzenBlazorDemos/Pages/GetStarted.razor at master Β· radzenhq/radzen-blazor Β· GitHub

Perhaps you can use a similar approach.

We really don't want to introduce API that relies on stored component references.

Yep binding works fine, I guess my code was doing the equivalent of this, but that won’t work.

No, that won't work. Assigning component parameters at runtime shouldn't trigger another render cycle (as it could lead to endless rendering loops). This is why data-binding should be used instead @bind-SelectedIndex=@selectedIndex.