【发布时间】:2011-05-06 01:49:48
【问题描述】:
嘿。
我有一个用户可以搜索的项目列表。搜索结果显示在列表框中。每个animal 对象都有一个指向独立存储中图像的路径。将 listboxitem 中的 Image 控件绑定到隔离存储中的图像的最快方法是什么?我见过的示例倾向于显示来自互联网而不是独立存储的图像。如果我有大约 10 张图像,它似乎会占用所有内存并崩溃。谢谢
编辑:
我在我的 BitmapConverter 类中使用它(继承 IValueConverter)
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value !=null)
{
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(new MemoryStream((Byte[]) value));
return bitmapImage;
}
else
{
return null;
}
}
我的 AppResource.xaml 文件顶部有这个:
<ImageApp_Converter:BitmapConverter x:Key="bmpConverter" />
In my style, within the AppResource.xaml file:
<Image HorizontalAlignment="Left" Margin="8,8,0,4" Width="160" Height="120" Source="{Binding Converter={StaticResource bmpConverter}}" />
我在 BitmapConverter 中设置了一个断点,但它从未被调用过。我以前从未使用过 IValueConverter,所以任何帮助都会很棒。谢谢
【问题讨论】:
-
您是否忘记了绑定中的路径?如果您绑定到您的 Datacontext(而不是从它的路径),您应该通过 {Binding .,Converter={...}} 或 {Binding Path=.,Converter={...}}提及它>
标签: c# silverlight binding windows-phone-7 isolatedstorage