I Vorlage Set für Artikel ListView
und ordnen ListenelementeWie aktuelle Element in ItemTemplate in Xamarin erhalten Forms
listView.ItemTemplate = new DataTemplate(typeof(CustomVeggieCell));
listView.ItemsSource = posts;
Wie currentItem
Element in CustomVeggieCell
erhalten:
CustomVeggieCell.class:
public class CustomVeggieCell : ViewCell
{
public CustomVeggieCell(){
// for example int count = currentItem.Images.Count;
var postImage = new Image
{
Aspect = Aspect.AspectFill,
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand
};
postImage.SetBinding(Image.SourceProperty, new Binding("Images[0]"));
var postImage = new Image
{
Aspect = Aspect.AspectFill,
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand
};
postImage.SetBinding(Image.SourceProperty, new Binding("Images[1]"));
}
}
Ich möchte die Menge Images
in ItemTemplate
erhalten. Images
ist einfach eine Liste von Strings.
p.s. Alle Werte in ItemTemplate
erhalte ich verbindlich.
Danke für die Antwort. Aber BindingContext ist immer Null, als ich versuchte, var allModel = BindingContext als WallPostViewModel zu erhalten; oder var images = (IList) BindingContext; In jedem Fall sind value und BindingContext null ... –
@IgorLevkivskiy Der 'CustomVeggieCell.BindingContext' bleibt' null', bis die 'ListView' mit' CustomVeggieCells' gefüllt ist und die Daten auf dem Bildschirm angezeigt werden. Versuchen Sie zu erklären, was Sie mit 'CustomVeggieCell.BindingContext' versuchen und vielleicht können wir Ihnen weiterhelfen. – hvaughan3
Ich möchte Bilder von currentItem erhalten, da jeder Beitrag unterschiedliche Anzahl an Fotos hat und deshalb möchte ich verschiedene Fotos für currentItem mit verschiedenen Layouts anzeigen. –