Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

[Xamarin.Forms] ListView with custom ViewCell containing an Image; How do I display an ImageSource?

$
0
0

Hi,

So, I have a ListView with custom ViewCell containing an Image and I've created a class called RateObject that looks like this:

`
public class RateObject
{
public String ImagePath {
get;
set;
}

    [Ignore]
    public ImageSource ImageSource {
        get;
        set;
    }

}
`

I use the [Ignore] annotation so that I can save the object to the database using SQLite ORM and I set the ImageSource when I have fetched the object from the database using the ImagePath.

So far so good, but the problem seem to be when I in my custom ViewCell, RateCell is trying to set the image.SourceProperty, it will not display an image. Why is that? I don't know, guessing it has to do with the [Ignore] annotation maybe?

`
public class RateCell : ViewCell
{
StackLayout rootCellView;
Image image;

    public RateCell ()
    {
        image = new Image {
            HeightRequest = 50,
            WidthRequest = 50
        };
        image.SetBinding(Image.SourceProperty, "ImageSource");
        rootCellView = new StackLayout{
            Orientation = StackOrientation.Horizontal,
            Children = {image}
        };
        View = rootCellView;
    }

}
`

Anyone know how to work around this?

(Code annotation seems bugged in the forum :()

Thanks,

Bobby Kristensen


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>