直接从手机获取设置

时间:2013-07-13 08:43:21

标签: c# windows-phone-8 application-settings

如何让我的代码直接从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中的页面设置更改为关闭但在我的应用程序中它仍然被视为真实。如何解决这个问题?

1 个答案:

答案 0 :(得分: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();         
   }