问题
I'm trying to achieve the following:
Now, this works perfectly fine, if I use it hard-coded like this:
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="WunderlistApp.View.MainPage"
NavigationPage.HasNavigationBar="False">
<!--Pages can be added as references or inline-->
<ContentPage Title="RallyPodium & Reporting" />
<ContentPage Title="Projecten voor klanten" />
<ContentPage Title="School" />
</TabbedPage>
Nown what I want to do, is I want to make those tabs "dynamically". What do I mean with this, is that I want to "link" the title from an API (data is bindable from the .cs file) to the xaml file (or make it in C#, but I have no clue how). And then the content must appear from it some way or another (it's just basically a listview)...
So if someoune could help me out here?
This is the .cs code:
public MainPage()
{
InitializeComponent();
//GetFolders();
}
private async Task GetFolders()
{
List<Folder> folders = await ApiManager.GetFoldersAsync();
//foreach (Folder f in folders)
//{
// Debug.WriteLine("Folder name: {0}", f.title);
//}
//lvwMainTasksList.ItemsSource = folders;
}
I also have no idea how I can link a contentPage to the tabbed pages?
回答1:
foreach (var f in folders) {
// if you are in code-behind of a TabbedPage, "this" will be TabbedPage
this.Children.Add(new ContentPage { Title = f });
}
来源:https://stackoverflow.com/questions/47397858/xamarin-dynamic-tabbed-page