I currently have a checkbox to adhere to MS location services rules, but it doesn't seem to save its state when you revisit the page.
Code is below:
private void cbLocationAllow_Checked(object sender, RoutedEventArgs e)
{
var settings = IsolatedStorageSettings.ApplicationSettings;
settings["allowLocation"] = true;
settings.Save();
}
private void cbLocationAllow_Unchecked(object sender, RoutedEventArgs e)
{
var settings = IsolatedStorageSettings.ApplicationSettings;
settings["allowLocation"] = false;
settings.Save();
}
I thought it would be something like..
private void SaveState(CheckBox checkBox)
{
var settings = IsolatedStorageSettings.ApplicationSettings;
if (settings.Contains("allowLocation"))
{
checkbox.isChecked == true;
}
But it doesn't seem to work and I'm looking for some help, once again.
The way I do it is to create a settings class, and bind the control to the property in the settings class. For simple programs, I use this method even for things that aren't really "settings", but just data that I need to have saved. In a couple cases, I have data that might be changed by another page, so for data that might be changed while not on the original page (in which case the NotifyChanged event doesn't fire because the page isn't in scope), I have code behind that goes back and checks the saved data.
Here's an example of the settings class similar to what I use:
http://msdn.microsoft.com/en-us/library/ff769510%28v=VS.92%29.aspx
I don't really understand the problem. but if you do this,
settings.Save();
then you save the settings. So if you browse through that part again, just load it back. Do not try to change the isChecked function of the checkbox.
or you can try to bind the isChecked of the checkbox to a local boolean variable. then save that in your database. if you load it again you can try adding this before or while loading.
cbLocationAllow.IsChecked = settings["allowLocation"];
Let me know if you need anything else.
Try using Mat laceys Tombstone helper, it makes saving the state of all Silverlight pages very easy to do, in fact in most cases it is just two lines of code per page to do.
WP7 Tombstone helper