Reputation: 439
How to make my code to set and get setting directly from page Setting in Windows Phone?
if (IsolatedStorageSettings.ApplicationSettings.Contains("LocationConsent"))
{
if ((bool)IsolatedStorageSettings.ApplicationSettings["LocationConsent"] == true)
return;
else
{
MessageBoxResult result =
MessageBox.Show("Can I use your position?",
"Location",
MessageBoxButton.OKCancel);
if (result == MessageBoxResult.OK)
{
IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = true;
}
else
{
IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = false;
}
IsolatedStorageSettings.ApplicationSettings.Save();
}
}
else
{
MessageBoxResult result =
MessageBox.Show("Can I use your position?",
"Location",
MessageBoxButton.OKCancel);
if (result == MessageBoxResult.OK)
{
IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = true;
}else
{
IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = false;
}
IsolatedStorageSettings.ApplicationSettings.Save();
}
}
In this example I use location setting, then I realize when I set it true from my application it will change setting in page Settings to on too. But when I change my location Setting from page Settings in original Windows Phone to off but in my application it still readed as true. How to fix this?
Upvotes: 0
Views: 166
Reputation: 31
Try something like this:
if((IsolatedStorageSettings.ApplicationSettings.Contains("LocationConsent")) && ((bool)IsolatedStorageSettings.ApplicationSettings["LocationConsent"] == true))
{ return; }
else
{ MessageBoxResult result =
MessageBox.Show("This app accesses your phone's location. Is that ok?",
"Location",
MessageBoxButton.OKCancel);
if (result == MessageBoxResult.OK)
{IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = true; }
else
{IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = false; }
IsolatedStorageSettings.ApplicationSettings.Save();
}
Upvotes: 1