Carousel View not showing

故事扮演 提交于 2019-12-25 08:20:09

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/40607007/carousel-view-not-showing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!