[WinRT] IDisposable in ViewModel

Topics: Getting Started
Dec 22, 2012 at 2:10 PM

I'm new to using Caliburn Micro, so there are a few things I don't understand yet. I have a WinRT application that works, but I'm concerned about resource usage. Here's the situation:

I have a ViewModel that contains a "disposable" resource. I looked at disposing it in OnDeactivate, but I'm confused. The close Boolean is never true in OnDeactivate. I thought that would have been an indication that the ViewModel is getting shut down and I can Dispose my resource. Instead, as I navigate, I see the constructor being called multiple times as I navigate forward and back.

Thanks!
Stacy

Dec 25, 2012 at 4:17 PM

I was able to use a custom FrameAdapter as shown here: http://caliburnmicro.codeplex.com/workitem/193 to get Deactivate to close when I'm navigating back from a page. Unfortunately, I'm still confused about View and ViewModel lifetimes in WinRT applications. It still appears to me that when I navigate "back" in the page stack, that I'm getting a new instance of my view+viewmodel. I would have expected the view and viewmodel to be persistent.

So, if I navigate from A to B then back to A, B should close, but A (both viewmodel and view) should still be persisted and I should just get back to the existing instance. Is this an incorrect assumption? I'm okay if it is, I just need to adjust my understanding.

Thanks,
Stacy

Dec 26, 2012 at 10:13 PM

It seems that there's an issue with NavigationCacheMode. If I set in in XAML it doesn't seem to work. If I set in in the constructor of the class it works. When set to Enabled, I get the behavior that I expected. I'm not sure I see why that's happening yet, but for now, the issue seems like it's not related to Caliburn Micro.

Thanks!
Stacy