Reputation:
I have read most of the questions posted here like this CarouselView not showing the data and Xamarin Form: Carousel View not showing on CarouselView but still me i get no luck, i am doing this common monkey example https://blog.xamarin.com/flip-through-items-with-xamarin-forms-carouselview/ but when i run on the simulator i see nothing, when i give it a background color it shows it .I even tried a simple example to populate list of numbers in a CarouselView but still it wasn't displaying anything.What is exactly the problem?
This was my expectation , but still no luck :
My XAML
<Grid RowSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height=".3*"/>
<RowDefinition Height=".7*"/>
</Grid.RowDefinitions>
<cv:CarouselView ItemsSource="{Binding Zoos}" x:Name="CarouselZoos">
<cv:CarouselView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Image Grid.RowSpan="2" Aspect="AspectFill" Source="{Binding ImageUrl}"/>
<StackLayout Grid.Row="1" BackgroundColor="#80000000" Padding="12">
<Label TextColor="White" Text="{Binding Name}" FontSize="16" HorizontalOptions="Center" VerticalOptions="CenterAndExpand"/>
</StackLayout>
</Grid>
</DataTemplate>
</cv:CarouselView.ItemTemplate>
</cv:CarouselView>
<!--List of Monkeys below-->
</Grid>
My C#
Model Class public class Zoo
{
public string ImageUrl { get; set; }
public string Name { get; set; }
}
MainActivity.cs
public class MonkeysViewModel
{
public ObservableCollection<Monkey> Monkeys { get; set; }
public ObservableCollection<Grouping<string, Monkey>> MonkeysGrouped { get; set; }
public ObservableCollection<Zoo> Zoos { get; set; }
public MonkeysViewModel()
{
Monkeys = MonkeyHelper.Monkeys;
MonkeysGrouped = MonkeyHelper.MonkeysGrouped;
Zoos = new ObservableCollection<Zoo>
{
new Zoo
{
ImageUrl = "http://content.screencast.com/users/JamesMontemagno/folders/Jing/media/23c1dd13-333a-459e-9e23-c3784e7cb434/2016-06-02_1049.png",
Name = "Woodland Park Zoo"
},
new Zoo
{
ImageUrl = "http://content.screencast.com/users/JamesMontemagno/folders/Jing/media/6b60d27e-c1ec-4fe6-bebe-7386d545bb62/2016-06-02_1051.png",
Name = "Cleveland Zoo"
},
new Zoo
{
ImageUrl = "http://content.screencast.com/users/JamesMontemagno/folders/Jing/media/e8179889-8189-4acb-bac5-812611199a03/2016-06-02_1053.png",
Name = "Phoenix Zoo"
}
};
}
}
Upvotes: 0
Views: 1373
Reputation: 3990
Ok , me too i had the same problem but this is how i solved mine but i don't know why.
STEP 1:
Check the Packages Folder under your projectname , right click on it and click add package , then search Xamarin.Forms.CarouselView then install it (version 2.3.0 pre 1).
STEP 2:
Check also under projectname.IOS and projectname.DROID the Packages Folder, also right click on it and click add package , then search Xamarin.Forms.CarouselView then install it (version 2.3.0 pre 1).
NOTE:
Install the same version Don't forget this.
Then run the App and see the output , hope it helps :-)
Happy Coding
Upvotes: 1