我想在隔离存储中存储多个名称。我将此代码用于存储多个存储
if (!setting.Contains("CityDetail"))
{
setting.Add("CityDetail", cityname);
}
else
{
setting["CityDetail"] = cityname;
}
setting.Save();
但它只给出了最后一个附加值,h =那么如何获取所有数据库值呢?
答案 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);