CancelViewModel上的复杂模型结构和InvalidOperationException

时间:2015-02-06 11:55:34

标签: c# mvvm model invalidoperationexception catel

我在viewmodel中有一个与此类似的模型体系结构(跳过实现,因为它不相关):

public ObservableCollection<Filetype> Filetypes

[Model]
public Filetype Filetype

[ViewModelToModel("Filetype")]
public ObservableCollection<DocumentType> DocumentTypes

[Model]
public DocumentType DocumentType

public ObservableCollection<Library> Libraries

[Model]
[ViewModelToModel("DocumentType")]
public Library Library

[ViewModelToModel("Library")]
public ObservableCollection<ContentType> ContentTypes

[ViewModelToModel("DocumentType")]
[Model]
public ContentType ContentType

此概念没有错误,标记为[Model] 的所有内容都成为一个模型。当然,FiletypeLibraryDocumentTypeContentType都代表了各自馆藏的选定值(在视图中)。

当我设置ContentType,然后关闭我的窗口(DataWindow.OnClosing期间)时,我的问题就出现了。 InvalidOperationException: the collection has been modifiedViewModelBase.CancelViewModel

类似于this reported bug,即ContentTypeDocumentType 的属性,Library.ContentTypes的成员,我认为这会产生问题清洁所有已注册的型号时。

查看评论,我尝试了解决方案(将Model(SupportIEditableObject:=False)设置为DocumentType,从ContentType中删除[Model],甚至一次删除所有这些内容),但没有成功。

如何在我的viewmodel中保留此模型结构?我是否必须为DocumentType创建另一个viewmodel?

0 个答案:

没有答案