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

ViewCell Binding Image

$
0
0

Hi! I'm very new in C# and Xamarin and now i have some problems.

I create an item class that includes an image.

        new Item {Id="10000", Name = "Pears", "Sub=Subu Sub", mainImage = new Image{Source="i10001.png"}};

This item objects are in an ObservableCollection and this collection is the source of my viewList. This viewList has a dataTemplate called ListItemCell. In this class i like to access the properties of my item instances. This works perfect with the string but i have no idea how i can receive the mainImage?

First I had the imageUri as string in the item class and the following solution. But with this i had a big memory problem, I think this was because every time I changed something in the list all images were reloaded? Is it possible, that when i change something in the ObservableCollection that this calls a methode in the ListItemCell class, so I can for example change the height of involved cell?

    Image image = new Image
    {
        HorizontalOptions = LayoutOptions.Start
    };


    image.SetBinding(Image.SourceProperty, new Binding("imageUri"));
    image.WidthRequest = image.HeightRequest = 50;

    StackLayout nameLayout = CreateNameLayout();
    StackLayout viewLayout = new StackLayout()
    {

        Orientation = StackOrientation.Horizontal,
        Children = {  image,nameLayout }
    };

I hope my question is not too confusing. Thanks!


Viewing all articles
Browse latest Browse all 58056

Trending Articles