1

After my wonderings on the events registration (you can find here ViewModel Event Registration and ViewModel Lifetime), now I'm thinking about viewmodel tombstoning:

In case of Tombstoning, is the ViewModel serialization a good approach ? I'm thinking about the case in which different viewmodels have a reference to the same class. In case of Viewmodels serialization and deserialization the referenced class instance could have duplicated instance, isn't it ?

Wouldn't be better to have specialized state classes whose unique purpose in to contain all the app data, everyviewmodel get data (i mean reference to the data) from there and update the data in there and the app think only to serialize those specialized class ?

Any experience on this subject is appreciated.

Regards SkyG

Community
  • 1
  • 1
SkyG
  • 275
  • 3
  • 11

1 Answers1

1

Caliburn Micro has a lot of this built in to the framwork allowing you to save properties of a view model or the entire graph to both phone state and app settings. You just need to create a class and inherit from StorageHandler.

public class PivotPageModelStorage : StorageHandler<PivotPageViewModel> 
{  
    public override void Configure() 
    {  
        this.ActiveItemIndex().InPhoneState().RestoreAfterViewLoad();  
    }  
}  

And to your other posted question. CM has a nice way of handling the forced view first approach on the phone. It allows you to do page navigation by specifying the VM and it will handle the rest. And as a bonus, if you specify parameters to pass CM will pull them off the query string and populate properties on the target VM.

public void GotoPageTwo() 
{  
    navigationService.UriFor<PivotPageViewModel>().WithParam(x => x.NumberOfTabs, 5).Navigate();  
}   
MyKuLLSKI
  • 5,285
  • 3
  • 20
  • 39
Derek Beattie
  • 9,429
  • 4
  • 30
  • 44
  • I tried caliburn.micro once, it is promising, I only found it contraining a little too much. Its ok for waht it is made for, but i'm still not feel confident for a production project, I fear about some surprise in the middle of the project and I prefer to use very light toolkit for now. Probably its worth to look how StorageHandler work to get some nice idea, so thank you! – SkyG Feb 09 '12 at 17:44
  • It's light, that's why it's called Micro :) Actually, I believe the author is working on what you're talking about. Breaking things out into even smaller pieces so you're able to use the things you want. – Derek Beattie Feb 09 '12 at 17:50