0

如何让我的代码直接从 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();
    }
}

在此示例中,我使用位置设置,然后我意识到当我从我的应用程序将其设置为 true 时,它​​也会将页面设置中的设置更改为 on。但是,当我将我的位置设置从原始 Windows Phone 中的页面设置更改为关闭时,但在我的应用程序中它仍然显示为 true。如何解决这个问题?

4

1 回答 1

1

尝试这样的事情:

   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();         
   }
于 2013-08-06T18:38:29.323 回答