chaosifier / TabView

TabView control for Xamarin.Forms.
MIT License
124 stars 32 forks source link

Add ability to use control from xaml. #6

Closed rjantz3 closed 6 years ago

rjantz3 commented 6 years ago

For those of us who want to use this control in xaml. The tab items can be defined in xaml in the following code example.

<ContentPage 
    xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    xmlns:views="clr-namespace:TabViewTest.Views"
    x:Class="TabViewTest.Views.MyContentPage"
    x:Name="MyContentPage"
    <ContentPage.Content>
        <views:TabViewControl BindingContext="{Binding BindingContext, Source={x:Reference MyContentPage}}">
            <views:TabViewControl.TabItems>
                <x:Array Type="{x:Type views:TabItem}">
                    <views:TabItem HeaderText="Tab1">
                        <views:TabItem.Content>
                            <views:Tab1CustomView/>
                        </views:TabItem.Content>
                    </views:TabItem>
                    <views:TabItem HeaderText="Tab2">
                        <views:TabItem.Content>
                            <views:Tab2CustomView/>
                        </views:TabItem.Content>
                    </views:TabItem>
                    <views:TabItem HeaderText="Tab3">
                        <views:TabItem.Content>
                            <views:Tab3CustomView/>
                        </views:TabItem.Content>
                    </views:TabItem>
                </x:Array>
            </views:TabViewControl.TabItems>
        </views:TabViewControl>
    </ContentPage.Content>
</ContentPage>

I also think this fixes the binding context mentioned in issue #5.

masiri201 commented 6 years ago

And it has functionality, does it run the code behind of the page in the tab?

masiri201 commented 6 years ago

I get this error: Gravidade Código Descrição Projeto Arquivo Linha Estado de Supressão No property, bindable property, or event found for 'Content', or mismatching type between value and property

<views:TabViewControl HeaderSelectionUnderlineColor="{StaticResource Custom Orange}" HeaderBackgroundColor="Transparent" BindingContext="{Binding BindingContext, Source={x:Reference DetailPage}}">

masiri201 commented 6 years ago

Well the Binding Context and the code is running fine, thanks I'm using your code for the time being until @chaosifier accepts the merge request, while you're at it to fix the delay when sliding you need to set the position in the positionchanging Event args like this:

private void _carouselView_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == nameof(_carouselView.Position) && !_supressCarouselViewPositionChangedEvent) { var positionChangingArgs = new PositionChangingEventArgs() { Canceled = false, NewPosition = _carouselView.Position, OldPosition = _position };

            OnPositionChanging(ref positionChangingArgs);

            if (positionChangingArgs != null && positionChangingArgs.Canceled) {
                _supressCarouselViewPositionChangedEvent = true;
                _carouselView.PositionSelected -= _carouselView_PositionSelected;
                _carouselView.PropertyChanged -= _carouselView_PropertyChanged;
                _carouselView.Position = _position;
                _carouselView.PositionSelected += _carouselView_PositionSelected;
                _carouselView.PropertyChanged += _carouselView_PropertyChanged;
                _supressCarouselViewPositionChangedEvent = false;
            }
       ->     SetPosition(positionChangingArgs.NewPosition);
        }
    }

And also this is personal preference but i set the underline box to fill the grid column i think it looks better that way.

chaosifier commented 6 years ago

Thank you @rjantz3 for your contribution! I really appreciate it.. And sorry for late response.

saickw commented 6 years ago

Can you provide a full example?

rraallvv commented 6 years ago

@rjantz3 , do you have a working example? I'm getting this error when trying to add TabViewControl in xaml.

jaimewyant commented 6 years ago

Is a working version of this going to be published to nuget anytime soon?

thiago-rcarvalho commented 6 years ago

Hey guys, any news about the nuget update? @chaosifier ?