I have a class that stores a ObservableCollection of BitmapImage's and I need to store this information in IsolatedStorage. I am using DataContract to do this with other class's which works. I am thinking that not being able to set the BitmapImage as a DataMember is stopping it from working.
Error message is:
Type 'System.Windows.Media.ImageSource' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute.
Any help would be appreciated.
CODE - Save to IsolatedStorage
public static void AddOrUpdateUnsavedItems(string key, List<ProcessClass> unsavedItems)
{
var store = IsolatedStorageFile.GetUserStoreForApplication();
if (store.FileExists("unsaveditem"))
{
store.DeleteFile("unsaveditem");
}
using (var stream = new IsolatedStorageFileStream("unsaveditem", FileMode.OpenOrCreate, FileAccess.Write, store))
{
DataContractSerializer dcs = new DataContractSerializer(typeof(List<ProcessClass>));
dcs.WriteObject(stream, unsavedItems);
}
}
CODE - Class
[DataContract]
public class ProcessClass
{
ObservableCollection<BitmapImage> images = new ObservableCollection<BitmapImage>();
[DataMember]
public ObservableCollection<BitmapImage> Images
{
get { return images; }
set { images = value; }
}
[DataMember]
public string Notes { get; set; }
[DataMember]
public string ItemID { get; set; }
}