Skip to content

[Question] ItemSource - simple example #41

@SorinMiron

Description

@SorinMiron

I want to render only the tabview, without the content from above. I tried and i figured out that TabItem shoud have content otherwise the app will crash.

I added from xaml some labels with following properties:


<tabview:TabItem HeaderText="Date 5" >
                        <Label HeightRequest="0" WidthRequest="0"></Label>
                    </tabview:TabItem>


All is working fine till now.

I'm trying to do the same thing dynamically from code.
Here is the example:

<tabview:TabViewControl
                HeaderBackgroundColor="SkyBlue"
                HeaderSelectionUnderlineColor="White"
                HeaderTabTextColor="White"
                HeaderTabTextFontAttributes="Bold"
                HorizontalOptions="FillAndExpand"
                IsSwipeEnabled="True"
                TabHeaderSpacing="100"
                VerticalOptions="FillAndExpand"
                ContentHeight="100"
                ItemSource="{Binding TabItems}"
               >

I added TabItems to Item Source.

I declared the variables into view model ( the binding is made to viewmodel)

 private ObservableCollection<TabItem> _tabItems;
        public ObservableCollection<TabItem> TabItems
        {
            get
            {
                return _tabItems;
            }
            set
            {
                _tabItems = value;
                OnPropertyChanged("TabItems");
            }
        }

And this is a method called on init

private void AddTabItemsByDate()
        {
            ObservableCollection<TabItem> tabs = new ObservableCollection<TabItem>();
            Label emptyLabel = new Label()
            {
                Text = "",
                WidthRequest = 0,
                HeightRequest = 0
            };
            tabs.Add(new TabItem("test1", emptyLabel));
            tabs.Add(new TabItem("test2", emptyLabel));
            tabs.Add(new TabItem("test3", emptyLabel));
            tabs.Add(new TabItem("test4", emptyLabel));

            TabItems = tabs;
        }

In the UI, i didn't see anything. The TabViewControl is empty, no tabs, no content, nothing.

I'm new at working with Xamarin. I'm wrong regarding the implementation? Should I use the template sample to do that? I didn't need the content from above, only the tabs.

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions