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 11:20 AM UTC

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 02:49 PM UTC

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 11, 2019 05:44 AM UTC

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



MA Mark February 21, 2020 03:32 AM UTC

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 01:06 PM UTC

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 02:39 PM UTC

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 12:24 PM UTC

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