【发布时间】:2014-09-26 19:45:15
【问题描述】:
我目前正在开始使用 Xamarin.Forms。我的页面上有一个 ListView,我绑定到我的 ViewModel。 ItemTemplate 的类型为“ImageCell”
绑定单元格的Text和Detail属性没有问题。但是,我无法绑定“ImageSourceProperty”。这是使用 byte[] 生成的图像源(我的图像是 SQLite 数据库中的 blob)
我想知道是否有人知道如何解决这个问题(或将 byte[]-image 绑定到 listview-item 的另一种方法)
这里有一些源代码:
var model = Graanziekten.Select(g => new OnkruidViewModel
{
Id = g.Id, Naam = g.Naam, Omschrijving = g.Omschrijving, Afbeelding = g.BitmapThumbnail
}).ToList();
var cell = new DataTemplate(typeof(ImageCell));
cell.SetBinding(TextCell.TextProperty, "Naam");
cell.SetBinding(TextCell.DetailProperty, "Omschrijving");
cell.SetBinding(ImageCell.ImageSourceProperty, "Afbeelding");
var listview = new ListView
{
ItemsSource = model,
ItemTemplate = cell
};
“BitmapThumbnail”属性定义为:
public ImageSource BitmapThumbnail
{
get
{
//AfbeeldingSmall is a byte[]
return ImageSource.FromStream(() => new MemoryStream(Afbeeldingen.First().AfbeeldingSmall));
}
}
如果我使用虚拟图像(来自 uri),它可以正常工作。但是,如果我使用上面显示的代码,则根本不会呈现内容页面(黑屏)。
起初我认为问题可能与 byte[] 是从属性中动态获取的事实有关,但是当我获取所有必要的 byte[] 时,也会出现同样的效果。
此外,当我将单个图像添加到我的内容页面时,使用相同的方法它确实有效。只是不在列表视图中。
我正在尝试在 WinPhone8 上执行此操作(尽管我认为平台并不重要)
提前致谢。
【问题讨论】:
标签: c# windows xamarin cross-platform xamarin.forms