How do I use a carouselview to display pictures where I have a list of URLs for the pictures?

awerberawerber Member ✭✭

I have a REST service on my web site that can supply a List of file names of pictures and I set up the URL. Currently, I do this to display the pictures:

        List<string> picFiles = calls.GetPictureFilesFromDirectory(actualDirectoryName);

        foreach (string fileName in picFiles)
        {
            string picFileWebAddress = calls.Domain + "Rodney/" + actualDirectoryName + "/" + fileName;
            var imgControl = new Image();
            imgControl.Source = picFileWebAddress;

            sl.Children.Add(imgControl); // sl is a StackLayout in a ScrollView
        }

How can I display the pictures in a CarouselView?

Thanks for any help

Tagged:

Answers

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    https://docs.microsoft.com/it-it/xamarin/xamarin-forms/user-interface/carouselview/

    I think it's the same of CollectionView... Set the ItemSource then create your Layout with an Image control. You can also use https://github.com/luberda-molinet/FFImageLoading control instead of Image

  • awerberawerber Member ✭✭

    Thank you for responding to my question. Your links have led me to some code/xaml regarding the carousel. Here's some XAML that I think is relevant:


    <CarouselView.ItemTemplate>




    My question is, how would I display multiple images? Would I repeat the outer Stack Layout, or the inner, or just add all the image controls to the inner Stack Layout? This code comes from https://docs.microsoft.com/en-us/samples/xamarin/xamarin-forms-samples/userinterface-carouselviewdemos/. I would just alter this code to see how to add multiple images, but the demo does not work.

  • awerberawerber Member ✭✭

    Sorry, the XAML was wiped out. It is attached.

  • awerberawerber Member ✭✭

    Now I'm trying something else in Main Page XAML:

    <?xml version="1.0" encoding="utf-8" ?>

    <StackLayout Margin="20">
        <SearchBar x:Name="searchBar"
                   SearchCommand="{Binding FilterCommand}"
                   SearchCommandParameter="{Binding Source={RelativeSource Self}, Path=Text}"
                   Placeholder="Filter" />
    
        <CarouselView>
            <CarouselView.ItemsSource>
                <x:Array Type="{x:Type x:String}">
                    <x:String>http://www.andrewwerber.com/Rodney/FirstWeekPictures/DSC_7591.jpg</x:String>
                    <x:String>http://www.andrewwerber.com/Rodney/FirstWeekPictures/DSC_7591.jpg</x:String>
                    <x:String>http://www.andrewwerber.com/Rodney/FirstWeekPictures/DSC_7591.jpg</x:String>
                    <x:String>http://www.andrewwerber.com/Rodney/FirstWeekPictures/DSC_7591.jpg</x:String>
                </x:Array>
            </CarouselView.ItemsSource>
        </CarouselView>
    </StackLayout>
    

    The only code in the cs file for the page is:

    InitializeComponent();

    I get the following exception when I start the project:

    System.TypeLoadException: Could not resolve type with token 01000005 from typeref (expected class 'ResourceLoadingQuery' in assembly '')

    I don't see much on this from a Google search, and what I've found does not seem relevant to my code.

Sign In or Register to comment.