enter code here
I have got isolated storage working but it's only storing one item.
I want to be able to store a list of favourites for the user to use in a list.
At the moment, i can store loads of stops, but when i open the application again, it only rememers the last item. and deletes the rest.
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");
}
then for displaying the list
if (IsolatedStorageSettings.ApplicationSettings.Contains("userData"))
{
listFav.Items.Add(IsolatedStorageSettings.ApplicationSettings["userData"] as string);
}
EDIT:
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;
}
displaying the data
if (IsolatedStorageSettings.ApplicationSettings.Contains("favourites"))
{
listFav.Items.Add(IsolatedStorageSettings.ApplicationSettings["favourites"] as List<string>);
}