Intenté mostrar una lista a Listbox por enlace de datos. Aquí está mi código.Serialización de Data-Bound ObservableCollection en WPF (PropertyChangedEventManager)
[Serializable]
public class RecordItem : INotifyPropertyChanged
{
//implements of INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
protected void Notify(string propName) { if (this.PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propName)); } }
}
[Serializable]
public class Records : ObservableCollection<RecordItem>
{
public UOCRecords() { }
public void Serialize(string path)
{
BinaryFormatter binForm = new BinaryFormatter();
using (FileStream sw = File.Create(path))
{
binForm.Serialize(sw, this);
sw.Close();
}
}
public static UOCRecords Deserialize(string path)
{
//...
}
}
funciona muy bien en el fondo, pero cuando el uso de los datos de unión
this.lbData.ItemsSource = myRecents;
y tratar de realizar serializar
this.myRecents.Serialize(recentsPath);
se produce este error:
Type 'System.ComponentModel.PropertyChangedEventManager' in Assembly 'WpfApplication1, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is not marked as serializable.
¿Cómo puedo manejarlo?
ps. No quiero serializar un controlador PropertyChangedEvent. Quiero marcar el atributo [NonSerializable] a eso, pero no sé cómo hacerlo.