0

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?

Kilazur
  • 3,089
  • 1
  • 22
  • 48
  • 1
    I think this is caused because you reset the collections (DocumentTypes / ContentTypes). You can always choose to map it manually. – Geert van Horrik Feb 06 '15 at 12:33
  • Actually, I don't know how to that in Catel. Does that mean I have to create a private variable `contentType` and such? In that case, `ContentType` won't be able to be a `[Model]`, and if so, would I have to map each of its properties the same way? – Kilazur Feb 06 '15 at 13:01
  • Yes, as you would need in any other fx. – Geert van Horrik Feb 06 '15 at 14:36
  • Yeah, I'm not saying it's a catel issue, I love it so far and blame my errors on the youth of my MVVM experience :p – Kilazur Feb 06 '15 at 14:53

0 Answers0