如何在wp7中的隔离存储设置中存储多个数据?

时间:2012-09-03 11:16:35

标签: windows-phone-7

我想在隔离存储中存储多个名称。我将此代码用于存储多个存储

if (!setting.Contains("CityDetail"))
            {

                  setting.Add("CityDetail", cityname);

            }
            else 
            {
                setting["CityDetail"] = cityname;


                           }
            setting.Save();

但它只给出了最后一个附加值,h =那么如何获取所有数据库值呢?

1 个答案:

答案 0 :(得分:2)

您可以使用这些功能将对象存储在手机申请状态

 public static void SaveState(string key, object value)
    {
        if (phoneApplicationPage.State.ContainsKey(key))
        {
            phoneApplicationPage.State.Remove(key);
        }

        phoneApplicationPage.State.Add(key, value);
    }

  public static object LoadState(this PhoneApplicationPage phoneApplicationPage, string key)
    {
        if (phoneApplicationPage.State.ContainsKey(key))
        {
            return phoneApplicationPage.State[key];
        }

        return null;
    }

编辑 - 使用隔离设置

   public void SaveCompositeObject()
   {
      var settings = IsolatedStorageSettings.ApplicationSettings;
      Person person= new City { Name = "Alex", Age= "21" };
      settings.Add("person", person);
   }

  public class Person
  {
     public string Name
     {
       get;
       set;
     }

    public string Age
    {
      get;
      set;
    }
}

检索数据

 Person person1;
 settings.TryGetValue<Person>("person", out person11);