Silverlight: IsolatedStorageSettings to persist data between page refresh
I am using IsolatedStorageSettings
class to store some application data that should be retained after page refresh of my Silverlight Navigation Application.
The data is stored in page FirstPage.xaml and is retrieved in SecondPage.xaml.
The following code works just fine if I do not do a refresh. However if I do a refresh on the SecondPage.xaml (second page), the values are returning empty from AppStore. What could be the reason.
public static class AppStore
{
private static IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings;
public static String MyData
{
get
{
if (appSettings.Contains("MyData"))
{
return(appSettings["MyData"].ToString());
}
return String.Empty;
}
set
{
if (!appSettings.Contains("MyData"))
{
appSettings.Add("MyData", string.Empty);
}
appSettings["MyData"] = value;
}
}
}
public partial class FirstPage : Page
{
private string data = "somevalue";
.
.
public FirstPage()
{
开发者_Python百科 AppStore.MyData = data;
}
}
public partial class SecondPage : Page
{
public SecondPage()
{
ContentText.Text = AppStore.MyData;
}
}
You're not saving the modifications in the IsolatedStorageSettings File, you should use this
IsolatedStorageSettings.ApplicationSettings.Save();
Note that you can use IsolatedStorageSettings.ApplicationSettings instead of a new instance of IsolatedStorageSettings. also don't save on each modification to your settings, just call this method in your App.Exit() event handler, saving data to the hard disk is time consuming.
精彩评论