这是我现在拥有的:
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
中确实为空。我做错了什么?