Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# CancelViewModel上的复杂模型结构和InvalidOperationException_C#_Mvvm_Model_Invalidoperationexception_Catel - Fatal编程技术网

C# CancelViewModel上的复杂模型结构和InvalidOperationException

C# CancelViewModel上的复杂模型结构和InvalidOperationException,c#,mvvm,model,invalidoperationexception,catel,C#,Mvvm,Model,Invalidoperationexception,Catel,我在viewmodel中有一个与此类似的模型体系结构(跳过实现,因为它不相关): 公共ObservableCollection文件类型 [型号] 公共文件类型文件类型 [视图模型模型(“文件类型”)] 公共可观察收集文档类型 [型号] 公共文档类型文档类型 公共图书馆 [型号] [视图模型模型(“文档类型”)] 公共图书馆 [ViewModelToModel(“库”)] 公共可观测集合内容类型 [视图模型模型(“文档类型”)] [型号] 公共ContentType ContentType 在这

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

公共ObservableCollection文件类型
[型号]
公共文件类型文件类型
[视图模型模型(“文件类型”)]
公共可观察收集文档类型
[型号]
公共文档类型文档类型
公共图书馆
[型号]
[视图模型模型(“文档类型”)]
公共图书馆
[ViewModelToModel(“库”)]
公共可观测集合内容类型
[视图模型模型(“文档类型”)]
[型号]
公共ContentType ContentType
在这个概念上没有错误,所有标记为
[Model]
的东西在某一点上都是一个模型。当然,
Filetype
Library
DocumentType
ContentType
都表示各自集合的选定值(在视图中)

当我设置
ContentType
,然后关闭窗口(在
DataWindow.OnClosing期间)时,问题就出现了<代码>无效操作异常:集合已在
ViewModelBase.CancelViewModel
内修改

它类似于,即
ContentType
DocumentType
的属性,并且是
库的成员。ContentTypes
,我假设它在清理所有注册模型时会产生问题

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


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

我认为这是因为您重置了集合(DocumentType/ContentType)。你可以选择手动映射。事实上,我不知道如何在Catel中映射它。这是否意味着我必须创建一个私有变量
contentType
等等?在这种情况下,
ContentType
将无法成为
[模型]
,如果是这样,我是否必须以相同的方式映射其每个属性?是的,正如您在任何其他fx中所需要的那样。是的,我并不是说这是一个catel问题,到目前为止我很喜欢它,并将我的错误归咎于我年轻的MVVM体验:p
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