Xamarin Forms(IOS)中的图像滑块CarouselView问题

时间:2017-05-29 11:15:24

标签: c# ios xamarin.forms

我已经在CarouselView上阅读了这里发布的大部分问题,例如CarouselView not showing the dataXamarin Form: Carousel View not showing,但我仍然没有运气,我正在做这个常见的猴子示例 { {3}}但是当我在模拟器上运行时我什么都没看到,当我给它一个背景颜色它显示它。我甚至尝试了一个简单的例子来填充CarouselView中的数字列表,但它仍然没有显示任何东西。问题究竟是什么?

这是我的期望,但仍然没有运气:

  1. Xamarin.Forms.CarouselView 的预发行版有问题还是因为我看到它有两个版本我必须选择一个? (但我尝试了每一个但仍然没有运气)
  2. 我应该使用CarouselView.FormsPlugin而不是Above,如果是这样,我应该采取什么明确的协议来实现这一目标?
  3. 我的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#
    

    模型类 公共类动物园

    {
        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"
                }
            };
        }
    }
    

1 个答案:

答案 0 :(得分:1)

好吧,我也有同样的问题,但这就是我解决了我的问题,但我不知道为什么。

第1步:

检查项目名称下的软件包文件夹,右键单击它并单击添加软件包,然后搜索 Xamarin.Forms。 CarouselView 然后安装它(版本 2.3.0 pre 1 )。

第2步:

同时检查 projectname.IOS projectname.DROID 文件夹,同时右键单击它并单击添加包,然后搜索 Xamarin.Forms.CarouselView 然后安装它(版本 2.3.0 pre 1 )。

注意:

安装相同版本不要忘记这一点。

然后运行应用程序并查看输出,希望它有所帮助:-)

快乐编码