4
votes

I have a relatively simple app in xamarin forms that has a ListView with custom cells. In these cells, there is an image. The problem that I am having is this. When I scroll the ListView, I can see the image from previous cells for a moment before the new images are loaded.

I have tried setting the ListView's ListViewCachingStrategy to all possible values but the problems persists.

Is there a way to stop the recycling? I know that it is a performance hit but the list is not that large. Unless ,of course, there is a better way to stop this image problem

3

3 Answers

2
votes

You could override OnBindingContextChanged ViewCell's method instead using bindings. Something like that:

protected override void OnBindingContextChanged()
{
    image.Source = null;

    base.OnBindingContextChanged();

    var item = BindingContext as YourItemType;

    if (item == null)
        return;

    image.Source = item.YourImageSource;
}

Read more here: https://developer.xamarin.com/guides/xamarin-forms/user-interface/listview/performance/#RecycleElement

1
votes

I haven't explicitly tried this as yet but if you attach on the ItemDisappearing event on the ListView.

Then get the e.Item and clear out the Image, so that it should update the Image in the cell with something blank.

Then when it comes back into view again, it should be blank before loading up with something new.

0
votes

What we have done about this problem is to set the binding image to a null value while the user is scrolling this force the image to render again, is not a good solution but it works.