Validating Application Settings Key Values in Isolated Storage for Windows Phone Applications
- by Martin Anderson
Hello everyone. I am very new at all this c# Windows Phone programming, so this is most probably a dumb question, but I need to know anywho...
IsolatedStorageSettings appSettings =
IsolatedStorageSettings.ApplicationSettings;
if (!appSettings.Contains("isFirstRun"))
{
firstrunCheckBox.Opacity = 0.5;
MessageBox.Show("isFirstRun not found - creating as true");
appSettings.Add("isFirstRun", "true");
appSettings.Save();
firstrunCheckBox.Opacity = 1;
firstrunCheckBox.IsChecked = true;
}
else
{
if (appSettings["isFirstRun"] == "true")
{
firstrunCheckBox.Opacity = 1;
firstrunCheckBox.IsChecked = true;
}
else if (appSettings["isFirstRun"] == "false")
{
firstrunCheckBox.Opacity = 1;
firstrunCheckBox.IsChecked = false;
}
else
{
firstrunCheckBox.Opacity = 0.5;
}
}
I am trying to firstly check if there is a specific key in my Application Settings Isolated Storage, and then wish to make a CheckBox appear checked or unchecked depending on if the value for that key is "true" or "false". Also I am defaulting the opacity of the checkbox to 0.5 opacity when no action is taken upon it.
With the code I have, I get the warnings
Possible unintended reference comparison; to get a value comparison, cast the left hand side to type 'string'
Can someone tell me what I am doing wrong. I have explored storing data in an Isolated Storage txt file, and that worked, I am now trying Application Settings, and will finally try to download and store an xml file, as well as create and store user settings into an xml file. I want to try understand all the options open to me, and use which ever runs better and quicker