2
votes

I'm using Xamarin Forms and Xamarin Android.

I've this code for reading some files (stored inside an Android Phone)

public ImageSource Photo { get; set; }

public void LoadPhoto()
{
    var t = Android.Net.Uri.Parse("URI_OF_THE_PHOTO");
    var otherStream = Android.App.Application.Context.ContentResolver.OpenInputStream(t);
    Photo = Xamarin.Forms.ImageSource.FromStream(() => otherStream);
}

then, in my XAML Page, inside a ListView's ViewCell i have this Image control:

<Image Source="{Binding Photo}"></Image>

Eveything works perfectly, the images (about 50) are loaded correctly and displayed inside the ListView.

BUT when i scroll the ListView and the images go out of the screen, when i scroll them back, they're EMPTY ! Images are suddendly gone... DISAPPEARED !!!

I've found a couple of StackOverflow's cases similar to this, but i can't get it to work with those solutions, they seem to not apply to my case.

Please, help, i'm stuck with this problem !

3
Try looking at the CachingStrategy for the ListViewGerald Versluis
unfortunately, I already tried setting it, with all its possible values ( RecycleElement / RetainElement / RecycleElementAndDataTemplate ) but it doesn't solve the problem at all :-(Alessandro
you can try using FFImageLoading plugin. That can help you cache the imagesOluwasayo Babalola
Have you also tried setting the CachingEnabled property of the image to true ?Oluwasayo Babalola
You can read this, so you get the images from uri? And you want to use FFImageLoading to load the image from uri?Robbit

3 Answers

1
votes

You can read this link. FFImageLoading will solve your problem.

1
votes

Use bindable stacklayout in xamarin forms 3.5..i had the same issue..solved..

0
votes

I have similar problem, and after Google for a while, problem solved.(maybe this answer is too late)

public ImageSource ByteToImageSource(byte[] byteArrayIn)
{
    //this way, image in ListView will disapear on scroll
    //var stream = new MemoryStream(byteArrayIn);
    //var retSource = ImageSource.FromStream(() => stream);

    // this way is fine
    var retSource = ImageSource.FromStream(() => new MemoryStream(byteArrayIn));
    return retSource;
}

so I think in your case, you could do like this:

Photo = Xamarin.Forms.ImageSource.FromStream(() => Android.App.Application.Context.ContentResolver.OpenInputStream(t));