ViewModelLocator or what ? Losing Data from another VIew

Topics: Getting Started
Nov 22, 2012 at 12:57 AM
Edited Nov 22, 2012 at 1:23 AM

Hello, I have a very simple problem but I cant find any solution. In first VIew I have ListBox of items and button adding one item. In second View i have only button to go back. Whenever I add data to ListBox with that button everything is correct. But when I navigate to second view and back, I am losing every Data i added because FirstViewModel is created second time. Previously i used MVVM Light and ViewModelLocator to register all ViewModels so that, when i navigated to another VIew, it wasn't created once more. How to do that in Caliburn.Micro WINRT?

Second question: Maybe it is better idea to keep that list which is binded to listbox as global, so it will not be recreated all the time? 

Nov 22, 2012 at 1:43 AM

How are you registering your ViewModels now?

Nov 22, 2012 at 10:15 AM
Edited Nov 22, 2012 at 11:17 AM

I don't register them. Just add them to my project. How to do that and what is the purpose to do that?

edit: ok i found solution. I can register my Viewmodel as singleton using function from WinRTContainer called RegisterSingleton. Is it good practice to do that? 

My second question is, what is the purpose of using RegisterPerRequest? If i don't register my Viewmodel with this function there are no differences. 

Nov 22, 2012 at 11:53 PM

RegisterPerRequest, is used when you don't want the viewmodel to be used again.  So think of it as NonShared in the MEF world.

Dec 8, 2012 at 2:56 PM
Edited Dec 8, 2012 at 8:42 PM

The WinRT version of simple container has some issues, as when the type is not registered, it creates an instance instead of returning null.

This should now be fixed by commit 27fe2a183a75.