Question

I'm just starting to work with windows 8 development (using c#), and am working on porting one of my applications to a windows store app. Essentially my application takes a user input string, calculates an appropriate output, and responds to the user. So I'm using a list view to track the "conversation." I display the user's input as a list view element and then display the output as the next element (using text blocks with formatting like color...).

What I would like to do is make this "conversation" persist once the app is terminated but am not sure the best way to do this. My first thought was to serialize the list view object on suspension then deserialize it on load, but the listview isn't serializable...So my next thought was to write out each input and output string to a file and try to rebuild the listview from these strings when I load the application, but I am having some issues with this as well.

So I'm curious as to what the best way to go about this is. I would like the application to start back up with the previous conversation already displayed with the same formatting and what not. Does anyone have any ideas?

Was it helpful?

Solution

I wouldn't persist the ListView anyway, you only need to persist the data in it. Are you using a MVVM type model, where your conversation is perhaps captured as an ObservableCollection and then bound to the ListView? If not, you should :)

Then you'd just need to serialize the ObservableCollection (see one option for that here). Where you persist it kind of depends on you:

  • LocalFolder would use a file based approach and be available on the local device
  • RoamingFolder would also use a file based approach but sync using the cloud across multiple devices that the user owns (and has the app installed)
  • Cloud storage (like Windows Azure or Windows Azure Mobile Services) would provide essentially boundless storage for you, but requires managing a cloud account and paying for it (though free tiers may be sufficient)
  • An in-memory database like SQLite is yet another option and would give you relational semantics should that be interesting to you.

To get started, I'd say use LocalFolder and persist your collection to a file, then when you rehydrate it, simple data binding should automatically handle the display. At some point, you may need to make a decision about how much to store. You want your application to be responsive for the user ('fast and fluid'), so to that end you may need to bring in data as it's requested versus all at once (perhaps a version 2 feature!)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top