I have a model architecture similar to this one in a viewmodel (skipping the implementation as it is not relevant):
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
There is no mistake on this conception, everything that is marked [Model]
has to be a model at one point. Of course, Filetype
, Library
, DocumentType
and ContentType
are all representing the selected value (in the view) of their respective collections.
My problem arises when I'm setting ContentType
, then closing my window (during DataWindow.OnClosing
). InvalidOperationException: the collection has been modified
, inside ViewModelBase.CancelViewModel
.
It is similar to this reported bug, i.e ContentType
is a property of DocumentType
and a member of Library.ContentTypes
, which I assume creates issues when cleaning all registered models.
Looking at the comments, I tried the solutions (setting Model(SupportIEditableObject:=False)
to DocumentType
, removing [Model]
from ContentType and even all of this at once), without success.
How can I keep this model structure in my viewmodel? Do I have to create another viewmodel for DocumentType?