Class 如何从其他类中的IsolatedStorage中检索值?

Class 如何从其他类中的IsolatedStorage中检索值?,class,windows-phone-7,boolean,isolatedstorage,Class,Windows Phone 7,Boolean,Isolatedstorage,我有两节课。首先是通过使用IsolatedStorage从ToggleSwitchButton存储布尔值 像这样 private void tglSwitch_Checked(object sender, RoutedEventArgs e) { System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings["EnableLocation"] = true; } pr

我有两节课。首先是通过使用IsolatedStorage从ToggleSwitchButton存储布尔值

像这样

    private void tglSwitch_Checked(object sender, RoutedEventArgs e)
    {
        System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings["EnableLocation"] = true;  
    }
    private void tglSwitch_Unchecked(object sender, RoutedEventArgs e)
    {
        System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings["EnableLocation"] = false;
    }
     if(booleanValFromFirst){
        //Do something
     }
     else{
        //Do something
     }
第二个类将使用第一个类中的布尔值来执行某些操作

像这样

    private void tglSwitch_Checked(object sender, RoutedEventArgs e)
    {
        System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings["EnableLocation"] = true;  
    }
    private void tglSwitch_Unchecked(object sender, RoutedEventArgs e)
    {
        System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings["EnableLocation"] = false;
    }
     if(booleanValFromFirst){
        //Do something
     }
     else{
        //Do something
     }

谢谢。

这是你想要的吗

if ((bool)System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings["EnableLocation"] == true)
另外,我建议您为所有值创建一个类,存储在应用程序设置中并使用它

像这样:

public static class SettingsManager
    {
        private static IsolatedStorageSettings appSettings;

        public static IsolatedStorageSettings AppSettings
        {
            get { return SettingsManager.appSettings; }
            set { SettingsManager.appSettings = value; }
        }

        public static void LoadSettings()
        {
            // Constructor
            if (appSettings == null)
                appSettings = IsolatedStorageSettings.ApplicationSettings;

            // Generate Keys if not created
            if (!appSettings.Contains(Constants.SomeKey))
                appSettings[Constants.SomeKey] = "Some Default value";

            // generate other keys             

       }
   }
然后您可以使用该类实例

在启动类中将其初始化为
SettingsManager.LoadSettings()

那么,在任何课程中,只要调用它:

if ((bool)SettingsManager.AppSettings[Constants.SomeBoolKey])
     doSomething();

谢谢你的回答,我明天会试试看。:)