我将图像存储为 byte[] 数组,因为我无法将它们存储为 BitmapImage。ShotItem 类将存储在 ObservableCollection 中的 IsolatedStorage 中。
namespace MyProject.Model
{
public class ShotItem : INotifyPropertyChanged, INotifyPropertyChanging
{
private byte[] _shotImageSource;
public byte[] ShotImageSource
{
get
{
return _shotImageSource;
}
set
{
NotifyPropertyChanging("ShotImageSource");
_shotImageSource = value;
NotifyPropertyChanged("ShotImageSource");
}
}
...
}
}
在我的 xaml 文件中,我有以下内容:
<Image Source="{Binding ShotImageSource}" Width="210" Height="158" Margin="12,0,235,0" VerticalAlignment="Top" />
不幸的是,我无法将图像作为字节直接加载到 xaml 中的 Image 容器中。我不知何故需要将 ShotImageSource 字节 [] 转换为 BitmapImage。我正在加载很多图像,所以这也必须异步完成。
我尝试使用转换器绑定,但我不确定如何让它工作。任何帮助将不胜感激 :)。