views:

418

answers:

4

I've tried to use IsolatedStorageSettings in my ViewModel, but these are not getting retained across browser refreshes (F5).

for example;

//look in the IsoStore for remembered details


    IsRememberMe = IsolatedStorageSettings.ApplicationSettings.Contains(Constants.LOGIN_REMEMBERED_USERNAME);

        if (IsRememberMe)
        {
            UserName = IsolatedStorageSettings.ApplicationSettings[Constants.LOGIN_REMEMBERED_USERNAME] as string;
        }

Do I need to do something differently in my MVVM ViewModel's??

EDIT It's worth noting that this code is sitting in a referenced project - so ultimately a seperate XAP file to the parent XAP that is loaded in the browser - might this cause the settings to be lost on each refresh?

THanks, Mark

A: 

I would think one of two things is happening here. Either your binding isn't working correctly in both directions so either the persistence or the retrieval code is never hit. Or, you're storing these values in application level iso storage from two different applications (or something to that effect). Make sure your code is being hit in both cases (storing and retrieving) and make sure you're accessing the iso store from the same place (if you're using application level isolation, store/retrieve from the same application, etc).

Rich
A: 

Thanks for taking time to respond Rich,

The code is definitely getting hit, and the value is persisted for the duration of the application - I can see this during debugging.

How would I check I'm "accessing the ISO store from the same place"? In code I'm only doing this from a ViewModel base class, at the moment this is always getting called by the same code, from the same XAP.

Mark Cooper
+1  A: 

Well...

In my case I have issues using Application Isolated Storage, each time I deployed a new version of my app (just for instance changing the color of a button I lost my Iso Storage :-().

I move to use SiteStorage instead of Application level, and it worked:

http://www.tipsdotnet.com/TechBlog.aspx?PageIndex=0&BLID=13

On the other hand what I had done with Iso Storage is perform CRUD on folders and files, not sure abou that other kind of settings.

HTH Braulio

Braulio
A: 

Thanks Braulio,

Long term I'm going to be storing user context data, so I'm not sure that Site Storage will meet my needs. I think I have to use Application Storage for that so it is not shared across users, have I got that right??

Mark

Mark Cooper
Mark, Site storage is still single user, the only thing is that you are going to have a single storage per site, and I guess 99 % of probabilities that you are going to have even a single XAP in your app,take a look at:http://msdn.microsoft.com/en-us/magazine/dd458794.aspxHTH Braulio
Braulio