I use Xamarin.Forms 4.3.0.778476-pre1
With this ItemsLayout the CarouselView should be work like this
<CarouselView.ItemsLayout>
<GridItemsLayout Orientation="Horizontal" SnapPointsAlignment="Center" SnapPointsType="Mandatory"/>
</CarouselView.ItemsLayout>

But on my sample i get the following

I use DataTemplateSelector for different views.
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:ShaXam"
xmlns:carouselStuff="clr-namespace:ShaXam.UIHelper"
xmlns:views="clr-namespace:ShaXam.Views"
x:Class="ShaXam.MainPage">
<ContentPage.Resources>
<ResourceDictionary>
<carouselStuff:CustomViewSelector x:Key="mySelector"/>
</ResourceDictionary>
</ContentPage.Resources>
<CarouselView ItemsSource="{Binding AvaiableViews}"
ItemTemplate="{StaticResource mySelector}">
<CarouselView.ItemsLayout>
<GridItemsLayout
Orientation="Horizontal"
SnapPointsAlignment="Center"
SnapPointsType="Mandatory"/>
</CarouselView.ItemsLayout>
</CarouselView>
</ContentPage>
public partial class MainPage : ContentPage
{
public List<Type> AvaiableViews { get; set; } // Must have default value or be set before the BindingContext is set.
private int _position;
public int Position { get { return _position; } set { _position = value; OnPropertyChanged(); } }
public MainPage()
{
InitializeComponent();
On<Xamarin.Forms.PlatformConfiguration.iOS>().SetUseSafeArea(true);
AvaiableViews = new List<Type>() { typeof(RecentView), typeof(ShaxamView), typeof(DiscoverView) };
BindingContext = this;
}
}
public class CustomViewSelector : DataTemplateSelector
{
private DataTemplate view1 = new DataTemplate(typeof(RecentView));
private DataTemplate view2 = new DataTemplate(typeof(ShaxamView));
private DataTemplate view3 = new DataTemplate(typeof(DiscoverView));
protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
{
// I don't use 'new' at every time as I do need to retain views status
Type currentView = item as Type;
if (currentView == typeof(RecentView))
return view1;
else if (currentView == typeof(ShaxamView))
return view2;
return view3;
}
}
The Android version is working good !!
Here is my demo
https://github.com/georgemichailou/ShaXam
Thanks for the sample @georgemichailou .
I've been testing and I've seen where us the problem. If you change the Layout from GridItemsLayout to ListItemsLayout:

It works as expected. The Carousel only supports ListItemsLayout. In the next Xamarin.Forms version ListItemsLayout changes its name to LinearItemsLayout and it will also be the only Layout that can be used in the Carousel (for now).
Thanks @jsuarezruiz for your time.
I update my solution to the new Xamarin.Forms 4.3.0819712-pre2
I use LinearItemsLayout now, but at the startup I get the following exception (android & ios)

Could you attach a repro sample?. I have updated the sample to 4.3.0819712-pre2 and I cannot reproduce the problem.

@jsuarezruiz Can you check again , please. Thanks
https://github.com/georgemichailou/ShaXam/commit/8cf89bd942bfdfc665cdc946f228179ba8b3141d
I have tried your latest sample (using 4.3.0819712-pre2) and everything works fine. Could you do clean and rebuild and try it again?. @PureWeen can you try the latest sample from George?
@georgemichailou I had the same result as @jsuarezruiz
Can you update to pre3 see how it works for you?
What device are you testing on specifically?
@PureWeen with pre3 is working perfect !! Thanks to all !!