简体   繁体   中英

Carousel View not showing

I created a CarouselPage but I need CarouselView so I can add other control onto the page. For some reason, nothing showing up. Don't know what I am missing.

public class Zoo
    {
        public string ImageUrl { get; set; }
        public string Name { get; set; }
    }

    public ObservableCollection<Zoo> Zoos { get; set; }

    public PlayKeySound()
    { 
        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"
            }
        };

        InitializeComponent();

        carousel.ItemsSource = Zoos;
    }

Xaml part:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    xmlns:control="clr-namespace:Xamarin.Forms;assembly=Xamarin.Forms.CarouselView"
    x:Class="keysound.PlayKeySound"
    x:Name="devicePage"
    BackgroundColor="Gray" >
<ContentPage.Content>
    <StackLayout  VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
        <control:CarouselView x:Name="carousel" >
            <control:CarouselView.ItemTemplate>
                <DataTemplate> 
                        <Label Text="{Binding Name}"/>
                </DataTemplate>
            </control:CarouselView.ItemTemplate>
        </control:CarouselView>
    </StackLayout>

</ContentPage.Content>

This is just a testing code to tryout the carousel view.

I was able to run your code and see the data of your collection. I had problems with carousel when I first time installed it. Try two things:

  1. Clean and rebuild the solution. If this doesn't help

  2. Uninstall pre-2, install pre-1. Check if it works. Then update to pre-2.

I know it is strange but that what did it for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM