【问题标题】:add images to carousel view in xamarin forms 4.4.0在 xamarin 表单 4.4.0 中将图像添加到轮播视图
【发布时间】:2020-03-10 19:18:29
【问题描述】:

我有这个用于创建轮播视图的代码

    <CarouselView x:Name="TheCarousel">
        <CarouselView.ItemsSource>
            <x:Array Type="{x:Type x:String}">
                <x:String>Hey...</x:String>
                <x:String>Psssst...!</x:String>
                <x:String>Did you check out...</x:String>
                <x:String>The awesome new CarouselView</x:String>
                <x:String>In Xamarin.Forms 4.4?!</x:String>
                <x:String>???? ????</x:String>
            </x:Array>
        </CarouselView.ItemsSource>
        <CarouselView.ItemTemplate>
            <DataTemplate>
                <StackLayout HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand">
                    <Label Text="{Binding .}" HorizontalTextAlignment="Center" FontSize="Title" />
                </StackLayout>
            </DataTemplate>
        </CarouselView.ItemTemplate>
    </CarouselView>`

我如何使用查看图像而不是字符串, 我在 Visual Studio 2019 上使用 xamarin 4.3.0

【问题讨论】:

    标签: c# xamarin xamarin.forms carousel


    【解决方案1】:

    在您的模板中使用Image 而不是Label

    <CarouselView x:Name="TheCarousel">
        <CarouselView.ItemsSource>
            <x:Array Type="{x:Type x:String}">
                <x:String>[image url goes here]</x:String>
                <x:String>[image url goes here]</x:String>
                <x:String>[image url goes here]</x:String>
            </x:Array>
        </CarouselView.ItemsSource>
        <CarouselView.ItemTemplate>
            <DataTemplate>
                <StackLayout HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand">
                    <Image Source="{Binding .}" />
                </StackLayout>
            </DataTemplate>
        </CarouselView.ItemTemplate>
    </CarouselView>`
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多