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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Thread ID:

Created:

Updated:

Platform:

Replies:

147409 Sep 10,2019 01:08 AM UTC Feb 21,2020 01:06 PM UTC Xamarin.Forms 5
loading
Tags: SfTabView
Robert
Asked On September 10, 2019 01:10 AM UTC

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.

Muneesh Kumar G [Syncfusion]
Replied On 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. 


Robert
Replied On 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.

Muneesh Kumar G [Syncfusion]
Replied On 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. 
 


Mark
Replied On 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!

Anandraj Selvam [Syncfusion]
Replied On 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. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon