Reputation: 1016
With Caliburn in WP81 when you navigate to a viewmodel and from there to another viewmodel, once you navigate back to the previous viewmodel the view is reloaded from scratch no matter what caching mode you set on the page.
Is there any way (or what's the best way) to somehow "cache" the previous view/viewmodel status when navigating back to it?
Upvotes: 1
Views: 922
Reputation: 16361
There is an open issue on Github regarding this, see https://github.com/Caliburn-Micro/Caliburn.Micro/issues/95. I describe my solution in a comment there https://github.com/Caliburn-Micro/Caliburn.Micro/issues/95#issuecomment-124473140.
Basically, you should use the CachingFrameAdapter
available in the 3.0.0 branch by directly using the 3.0.0 branch or taking the CachingFrameAdapter
out of it and using it in your code with the current Caliburn version (2.x).
If you take the second route as I did, add CachingFrameAdapter
to your project and replace the PrepareViewFirst
in your App.xaml.cs
to this
protected override void PrepareViewFirst(Frame rootFrame)
{
RegisterNavigationService(rootFrame);
}
public INavigationService RegisterNavigationService(Frame rootFrame, bool treatViewAsLoaded = false)
{
if (rootFrame == null)
throw new ArgumentNullException("rootFrame");
var frameAdapter = new CachingFrameAdapter(rootFrame, treatViewAsLoaded);
container.RegisterInstance(typeof(INavigationService), null, frameAdapter);
return frameAdapter;
}
Upvotes: 2