Stop Cell Recycling in Xamarin Forms ListView

I have a relatively simple xamarin format application that has a ListView with custom cells. These cells have an image. The problem I am facing is this. When I browse the ListView, I can see the image from the previous cells for a moment before loading new images.

I tried to set ListView ListViewCachingStrategyto all possible values, but problems persist.

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

+4
source share
3 answers

Instead, you can override the OnBindingContextChangedViewCell method 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;
}

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

+2
source

I have not tried this yet, but if you are joining the ItemDisappearing event in a ListView.

Then get e.Item and clear the image so that it updates the image in the cell with something empty.

Then, when it reappears in sight, it must be empty before loading anything new.

+1
source

, , , , , .

0
source

Source: https://habr.com/ru/post/1622696/


All Articles