To get the current item in ItemTemplate, you only need to reference it CustomVeggieCell BindContextlike this:
string imageString = (string)BindingContext; //Instead of string, you would put what ever type of object is in your 'posts' collection
, . CustomVeggieCell ListView, , :
new Binding("Images[1]")
ListView foreach . posts List<string>.
: , . , bindable ViewCell OnPropertyChanged, , ViewCell. , .
- :
public class CustomVeggieCell : ViewCell
{
public List<ImageSource> Images {
get { return (ImageSource)GetValue(ImagesProperty); }
set { SetValue(ImagesProperty, value); }
}
public static readonly BindableProperty ImagesProperty = BindableProperty.Create("Images", typeof(List<ImageSource>), typeof(CustomVeggieCell), null, BindingMode.TwoWay, null, ImageCollectionChanged);
private StackLayout _rootStack;
public InputFieldContentView() {
_rootStack = new StackLayout {
Children =
};
View = _rootStack;
}
private static void ImageCollectionChanged(BindableObject bindable, object oldValue, object newValue) {
List<ImageSource> imageCollection = (List<ImageSource>)newValue;
foreach(ImageSource imageSource in imageCollection) {
(CustomVeggieCell)bindable)._rootStack.Children.Add(new Image { Source = imageSource });
}
}
}
- . posts.Images bindable. , , .