1

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?

Igor Kulman
  • 16,211
  • 10
  • 57
  • 118
Pinco Pallino
  • 916
  • 1
  • 6
  • 18
  • Set the NavigationCacheMode property of your view to Enabled http://stackoverflow.com/questions/27689706/caliburn-micro-goback-to-previous-page-instance-winrt – Barnstokkr Sep 17 '15 at 12:39
  • Also have a look at http://stackoverflow.com/questions/11539755/winrt-frame-and-page-caching-how-to-create-new-page-instance-on-navigate-and – Rico Suter Sep 17 '15 at 12:45
  • Seems to work for caching the View, but the content is somehow reset (e.g.: a list that was scrolled to the bottom, it shows from the top once navigated back). – Pinco Pallino Sep 17 '15 at 19:34
  • Actually no, I'm using Caliburn 3 with CachingFrameAdapter and the viewmodel is not recreated but the view is recreated no matter what NavigationCacheMode I set. – Pinco Pallino Sep 17 '15 at 19:39

1 Answers1

2

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 CachingFrameAdapterto 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;
}
Igor Kulman
  • 16,211
  • 10
  • 57
  • 118
  • This works for caching the ViewModel, but still leaves me with the following issue: when I scroll down a list in a view, navigate forward, then backward, the list is displayed from the top. I would like the whole view to keep the state. – Pinco Pallino Sep 17 '15 at 19:33
  • 1
    This you have to handle yourself, take a look at http://kasperholdum.dk/2012/10/remember-scrollviewer-position/ – Igor Kulman Sep 17 '15 at 19:45