i need your help to know where i'm wrong..

I have a ContentPage with a listview populated by TextCell only. When i tap on an element it will invoke the command OpenPostEvent and it will update an image field inside a stacklayout. The image is generated by an ImageSource, like this:

<Image  BackgroundColor="Transparent"  Margin="20" HorizontalOptions="Center"  HeightRequest="130"  Aspect="AspectFit"  Source="{Binding imageSource}"></Image>

When i tap on an item into listview i invoke a command in the viewmodel:

private void OpenPostEvent(object itemchoose)
{
        Post post = (Post)itemchoose;            
        byte[] immagineByte = post.immaginePostByte;
        streamImmagine = new MemoryStream(immagineByte);
        imageSource = ImageSource.FromStream(() => streamImmagine);            
}

First time i tap an item in the listview the image is updating, then if i tap on another element on listview i get the error.. How i can retrieve the mainthread?

I used Davice.BeginInvokeOnMainThread but it doesn't work..

1

There are 1 best solutions below

0
Orion77 On

I found the solution in set imageSource variable to null before reload with new stream...

private void OpenPostEvent(object itemchoose)
{
        Post post = (Post)itemchoose;            
        byte[] immagineByte = post.immaginePostByte;
        streamImmagine = new MemoryStream(immagineByte);
        imageSource = null;
        imageSource = ImageSource.FromStream(() => streamImmagine);            
}