0
votes

I have this code for creating a carouselview

    <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>`

how can i use to view images instead of string , im using xamarin 4.3.0 on visual studio 2019

1

1 Answers

1
votes

use an Image instead of a Label in your template

<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>`