Xamarin CarouselView using the <ContentView> List
I'm trying to fill CarouselView List ContentView. Can anybody help?
I tried for 2 days, it is as close as I get, but I just get a blank page. In my tests, the new representations of the content actually contain data, but I missed this for simplicity. They display their content if I install them as content manually, but not using CarouselView.
CodeBehind
List<ContentView> viewList = new List<ContentView>();
viewList.Add(new ContentView()); //Data Entry for Book information
viewList.Add(new ContentView()); //Data Entry for Widget information
viewList.Add(new ContentView()); //Data Entry for Quijibo information
var myCarousel = new CarouselView.FormsPlugin.Abstractions.CarouselViewControl();
myCarousel.ItemsSource = viewList;
myCarousel.ItemTemplate = new DataTemplate(typeof(ContentView));
myCarousel.Position = 1; //default
myCarousel.Orientation = CarouselViewOrientation.Horizontal;
myContentPresenter.Content = myCarousel;
Xaml
<ContentPresenter x:Name="myContentPresenter" />
The second attempt, I thought that I would return to an example that works with Google Video search on YouTube from Houssem Dellai, and then change it as little as possible. Still getting a blank screen.
Code behind
var NameList = new List<ContentView>();
NameList.Add(new ContentViewBook());
NameList.Add(new ContentViewWidget());
NameList.Add(new ContentViewQuijibo());
//var NameList = new List<string> { "A", "B", "C" }; This works with XAML Label
mainCarouselView.ItemsSource = NameList;
Xaml
<controls:CarouselViewControl x:Name="mainCarouselView" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<controls:CarouselViewControl.ItemTemplate>
<DataTemplate>
<!--<Label Text="{Binding .}" /> This works with List<String>-->
<ContentView Content="{Binding .}" />
</DataTemplate>
</controls:CarouselViewControl.ItemTemplate>
</controls:CarouselViewControl>
, , . MR.Gestures MR.Gestures . , , , .
myContentView.Content = new ContentViewQuijibo();
XAML
<ContentView x:Name="myContentView" />
+4