这就是我现在所拥有的:
public ObservableCollection<ClientInfo> Clone(ObservableCollection<ClientInfo> clone)
{
MemoryStream ms = new MemoryStream();
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(ms, clone);
ms.Position = 0;
object obj = bf.Deserialize(ms);
ms.Close();
return obj as ObservableCollection<ClientInfo>;
}
void ItemList_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
ObservableCollection<ClientInfo> list = sender as ObservableCollection<ClientInfo>;
ItemList = Clone(list);
//MessageBox.Show("Event: CollectionChanged");
}
在调试器中sender
包含我的ObservableCollection,我可以看到所有的变量,它们似乎是正确的但是出于某种原因,手动将其转换为ObservableCollection似乎将其清空,因为我得到Argument Null Exception
并且在调试器list
确实为空。我做错了什么?