Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

Dynamically loading Shell TabBar Tabs

$
0
0

Hi,

Attached VS2019 (Windows) Shell solution is loading TabBar Tabs dynamically. The issue is TabBar.Tab.Items.Clear() results in page not loading in iOS, and in Android only one of the 2 tabs has data.

What am I doing wrong?

See AppShellViewModel.cs

Thank you.

` class AppShellViewModel: BaseViewModel
{
private ObservableCollection accounts = new ObservableCollection();

    public AppShellViewModel()
    {
        Task.Factory.StartNew(RefreshAccountListAsync);
    }

    public ObservableCollection<string> Accounts
    {
        get => accounts;
        set => SetProperty(ref accounts, value);
    }

    private void RefreshAccountListAsync()
    {
        IsBusy = true;
        Accounts = new ObservableCollection<string>(new List<string>() { "Account1", "Account2" });

        Tab resultsTab = PickerTestApp.AppShell.Current.FindByName<Tab>("resultsTab");
        Xamarin.Essentials.MainThread.BeginInvokeOnMainThread(() =>
        {
            //On Android, clearing Items works.
            //On iOS, app does not load at all
            resultsTab.Items.Clear();

            //On Andoid: Account2 never loads ItemsPage
            //On iOS, app does not load at all
            foreach (var account in Accounts)
            {
                ShellContent resultsSC = new ShellContent();
                resultsSC.Title = account.ToUpperInvariant();
                resultsSC.Route = account;
                resultsSC.ContentTemplate = new DataTemplate(() => { return new PickerTestApp.Views.ItemsPage(); });
                resultsTab.Items.Add(resultsSC);
            }
        });

        IsBusy = false;
    }

}`

Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>