Xamarin dynamic tabbed page

孤人 提交于 2019-12-25 18:48:58

问题


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 &amp; 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!