I have an issue with the tombstoning mechanism of Caliburn.Micro.
For example, I have three Views/ViewModels:
- MainPageViewModel: displays each item in a list
- DisplayPageViewModel: displays detailed item information
- MaintainPageViewModel: add or edit an item;
I navigate through MainPageVM, DisplayPageVM, and MaintainPageVM. Then, in MaintainPageVM I navigate back to DisplayPageVM via navigationService.GoBack();. In DisplayPageVM, I pin the item to start and I think at this time the MaintainPageVM gets tombstoned although it is not active anymore.
After that, I navigate back to MainPageVM and then navigate forward to MaintainPageVM to create a new item. A new instance of MaintainPageVM is created but the values from the instance before are restored. This does only occurre if I leave the app by pinning an item to start in the DisplayPageVM (tombstone).
This is my StorageHandler for the MaintainPageViewModel:
public class MaintainPageStorage : StorageHandler<MaintainPageViewModel>
{
public override void Configure()
{
Property(x => x.Message).
InPhoneState().
RestoreAfterActivation();
}
}
Could it be possible that I don't close my MaintainPageVM correctly so that the StorageHandler for this ViewModel is still active although the ViewModel was deactivated?
EDIT
I checked the documentation of Caliburn.Micro:
public class MaintainPageStorage : StorageHandler<MaintainPageViewModel>
{
public override void Configure()
{
Id(x => x.Name);
Property(x => x.Duration).
InPhoneState().
RestoreAfterActivation();
Property(x => x.Message).
InPhoneState().
RestoreAfterActivation();
}
}
I have to specify an Id. In this case, the tombstoned MaintainPageVM will not be restored if I naviagte to this ViewModel again to add a new item.
In another case, the problem is stil present: I navigate to DisplayPageVM to display an item, then navigate to MaintainPageVM to edit this item and go back without saving. In DisplayPageVM, I pin the item to start (MaintainPageVM gets tombstoned) and go to MaintainPageVm again. The tombstoned version is restored again.
So I have still the problem that the MaintainPageVM is in memory although I've already navigated back from it.