1
votes

I'm new to xamarin forms and i'd like to know the best approach to bind an image from uri in a listview.

The scenario is the following:

  1. A listview that get remote json data from a web services
  2. The json data contains many url
  3. Each cell get async the image and show it
  4. I want reuse of the cell

What's the best approach with xamarin forms? I haven't found any tutorial

1

1 Answers

1
votes

Here's a basic example, but basically, create a ListView, bind your collection of objects (the url field here is called ImageUrl), then set that as the source of an Image element in a ViewCell of your ItemTemplate:

<ListView ItemSource="{Binding MyCollectionOfThings}">
    <ListView.ItemTemplate>
        <DataTemplate>
            <Grid>
                <Image Source="{Binding ImageUrl}"/>
            </Grid>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>