enter code here
我有独立的存储工作,但它只存储一件物品。
我希望能够存储收藏夹列表供用户在列表中使用。
目前,我可以存储大量停靠点,但是当我再次打开应用程序时,它只会记住最后一项。并删除其余部分。
private void ApplicationBarFavouriteButton_Click(object sender, EventArgs e)
{
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
// txtInput is a TextBox defined in XAML.
if (!settings.Contains("userData"))
{
settings.Add("userData", busStopName.Text);
}
else
{
settings["userData"] = busStopName.Text;
}
settings.Save();
MessageBox.Show("Bus Stop was added to your favourites");
}
然后用于显示列表
if (IsolatedStorageSettings.ApplicationSettings.Contains("userData"))
{
listFav.Items.Add(IsolatedStorageSettings.ApplicationSettings["userData"] as string);
}
编辑:
private void ApplicationBarFavouriteButton_Click(object sender, EventArgs e)
{
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
List<string> favourites = settings["favourites"] as List<string>;
if (favourites == null)
{
favourites = new List<string>();
settings.Add("favourites", favourites);
}
favourites.Add(busStopName.Text);
settings["favourites"] = favourites;
}
显示数据
if (IsolatedStorageSettings.ApplicationSettings.Contains("favourites"))
{
listFav.Items.Add(IsolatedStorageSettings.ApplicationSettings["favourites"] as List<string>);
}