0
我正在创建一个自定义的ViewCell,以便在ListView中使用,就像我以前做过很多次一样。但是,这是我第一次需要在自定义ViewCell中使用图像,并且无法使其工作。Xamarin - 在自定义列表视图中使用图像ViewCell
所以,我有我的模型:
public class AttendedMeeting
{
public string Title { get; set; }
public string Date { get; set; }
public string Status { get; set; }
public Image MeetingImage { get; set;}
}
而且在我的自定义ViewCell:
Label titleLabel = new Label();
titleLabel.SetBinding(Label.TextProperty, "Title");
Label dateLabel = new Label();
dateLabel.SetBinding(Label.TextProperty, "Date");
Label statusLabel = new Label();
statusLabel.SetBinding(Label.TextProperty, "Status");
Image meetingImage = new Image();
meetingImage.SetBinding(Image.SourceProperty, "MeetingImage");
然后在我的网页,我填充对象的列表如下:
ListView meetingsListView = new ListView();
Image imageCheck = new Image();
imageCheck.Source = "Check.png";
Image imageLine = new Image();
imageLine.Source = "Line.png";
Image imageCircle = new Image();
imageCircle.Source = "Circle.png";
meetingsListView.ItemsSource = new AttendedMeeting[] {
new AttendedMeeting {Title = "Meeting 1",
Date="Monday - May 16th 2016",
Status="Verified",
MeetingImage=imageCheck
},
new AttendedMeeting {Title = "Meeting 2",
Date="Monday - May 16th 2016",
Status="Verified",
MeetingImage=imageLine
},
new AttendedMeeting {Title = "Meeting 3",
Date="Monday - May 16th 2016",
Status="Verified",
MeetingImage=imageCheck
},
new AttendedMeeting {Title = "Meeting 4",
Date="Monday - May 16th 2016",
Status="Verified",
MeetingImage=imageCheck
}
};
meetingsListView.ItemTemplate = new DataTemplate(typeof(CellMeetingsAttended));
除了图像以外,一切都很棒。标签填充得很好,但每个项目上的图像总是空白。谁能告诉我我做错了什么?我也尝试在模型中使用字符串而不是Image(),并使用字符串设置图像源,并且也没有运气。我已验证资源是否正确,我可以将它们显示为ListView外部的图像。
在此先感谢。
非常感谢。这工作加上它也导致我另一个领域,我没有正确设置来源,工程太棒了! – AS2012