We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Is There a Simple Way to Have a Dynamic Number of Tabs?

I would like to have a dynamic number of tabs in a tab view.  The number of tabs would depend on user entered data. Each tab would hold a ListView with different ListView items.

The Xamarin.Forms TabbedPage actually does this quite well but they have no setting to make the TabHeadings scrollable (that I have found).  With more than 3 or 4 tabs the UI looks very crumpled up.

I think I would see away in SFTabView to use a ContentView as a repeatable "user control" for the ListView but it looks pretty complicated.  I could probably also do this in C# and create the ListView in code behind but I try to limit my code behind to logic and event management and have UI elements defined in XAML.

I just wanted to check if there is a simpler way to do with SFTabView.  Unfortunately, all the SFTabView examples just show a static number of tabs with UI defined for each tab. 

Any input appreciated.

7 Replies

MK Muneesh Kumar G Syncfusion Team September 10, 2019 03:20 AM

Hi Robert, 
 
Greetings from Syncfusion.  
 
We have validated your query and prepared a sample based on your requirement. Please find the sample from below link. 
 
 
In the above sample, based on the user typed value TabItems are created with different list view items. 
 
Code snippet: 
 
private void Entry_TextChanged(object sender, TextChangedEventArgs e) 
        { 
              tabItemsCount = e.NewTextValue; 
              this.AddTabs(); 
        }   
 
// Add items dynamically.  
private void AddTabs() 
        { 
            if (tabItemsCount != null && tabItemsCount == "") 
            { 
                tabView.Items.Clear(); 
            } 
            else 
            { 
                tabView.Items.Clear(); 
                GenerateBookInfo(); 
                for (int i = 0; i < Convert.ToInt64(tabItemsCount); i++) 
                { 
                    SfTabItem tabItem = new SfTabItem(); 
                    tabItem.Title = string.Format("Page {0}", i + 1); 
                    var item = new ItemsPage(); 
                    item.model.BookInfo = Items[i]; 
                    tabItem.Content = item; 
                    tabView.Items.Add(tabItem); 
                } 
            } 
        } 
 
Please let us know, if you have any other queries. 
 
Thanks, 
Muneesh Kumar G. 



RO Robert September 10, 2019 06:49 AM

Thank you for that.  I had hoped there would be a not to difficult way to do this in XAML. I think it could be done with a ContentView (sort of like a UserControl) but with some time to work it all out.  If I get that done I may post the example back here.


MK Muneesh Kumar G Syncfusion Team September 10, 2019 09:44 PM

Hi Robert,  
  
Thanks for your update and we will wait to hear from you. 
  
Thanks, 
Muneesh Kumar G. 
 



MA Mark February 20, 2020 07:32 PM

Curious if you ended up with a different solution for this? I'm just trying it out myself, and not having any luck so far with the proposed approach above!


AS Anandraj Selvam Syncfusion Team February 21, 2020 05:06 AM

Hi Mark, 
 
Thanks for the update, 
 
Currently we don't have direct support or workaround as Tab View is populated with only of type Tab Items and we must manually create the tab items. 
 
Regards, 
Anand Raj S. 



DP Dean Puckett April 1, 2022 06:39 AM

Is there a way to do this via XAML rather than code behind, similar to a BindableLayout?



SS Suganya Sethuraman Syncfusion Team April 4, 2022 04:24 AM

Hi Dean,

We have analyzed your requirement. Currently, we don't have support for your requirement. We would like to inform you that we have considered this as a feature request “BindableLayout support for SfTabView” and you can track the status of this feature implemented through the below link.

Feedback link: https://www.syncfusion.com/feedback/33304

Please cast your vote to make it count. We will prioritize the features every release based on the demands, and we do not have an immediate plan to implement this feature since we committed to already planned work. So, this feature will be available in any of our upcoming releases.

If you have any more specifications/suggestions for the feature request, you can add them as a comment in the portal.

Regards,
Suganya Sethuraman.


Loader.
Live Chat Icon For mobile
Up arrow icon