0

这是我现在拥有的:

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中确实为空。我做错了什么?

4

0 回答 0