catel

Catel Edit Master-Detail View multiple times


I'm trying to edit a Master-Detail View multiple times in Catel.

My question is, if there is no common way in catel to handle a Master-Detail-View and multiple editions using the SaveViewModelAsync and CancelViewModelAsync methods?

The workflow works when my Master-ListItem is no UserControl with it's own ViewModel and when I change the selected Master-ListItem after save or cancel, so that a new ViewModel will be created. But I don't want to null or change the selection after a save/cancel. Also I have maybe to create a UserControl + ViewModel for the Master-ListItems.

Restrictions of the question:

I have got the information from Geert van Horrik from the discussion of his answer, that

Problem:

I can use the the SaveViewModelAsync and CancelViewModelAsync only once. After that, the ViewModels which are alive

Code to Reproduce:

I have created a WPF Project, where I tested this all.

Possible solution:

Restricion of the solution:

My conclusion:

It seems, that I have to instantiate all these ViweModels and handle this workflow all by myself. It seems, that the ViewModelLifetimeManagement.PartlyManual (CloseViewModelOnUnloaded is Obsolete) doesn't work here. On selection change, always a new ViewModel will be created, the old one will probably just not be closed.

I don't want to misuse the framework. Maybe I have missed something. I hope somebody can help me or give me a tip, how to handle this.


Solution

  • After the answer of Geert van Horrik, I currently ended up , don't using the SaveViewModelAsync and CancelViewModelAsync methods and handle the save and cancel by my own, so that the notification will not breake. I'm using the GetChildViewModels() method on the ViewModelBase and the EditableObjectHelper.CancelEditObject(Model);