This is actually a follow up to Storing data on Windows phone.
I have an app that loads a favourites page. If the favourites page is empty, the user can click a search button on the favourites page which loads a search page. There they can search for information and save it as a favourite. My code for saving the favourites is as follows.
stopNumber = txtBusStopNumber.Text;
IsolatedStorageSettings favouriteStops = IsolatedStorageSettings.ApplicationSettings;
if (!favouriteStops.Contains(stopNumber))
{
favouriteStops.Add(stopNumber, stopAddress);
favouriteStops.Save();
MessageBox.Show("Favourite saved!");
}
The way the app works, once the user has added their favourites, they will navigate back to the previous page (the favourites page). When they navigate back to the favourites page, it needs to load the information that has just been added to IsolatedStorage via the Search page.
I know the code needs to be in the OnNavigatedTo event of the favourites page, but the issue is, my code doesn't seem to be reading any data.
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (IsolatedStorageSettings.ApplicationSettings.Contains("stopNumber"))
{
for (int i = 0; i < IsolatedStorageSettings.ApplicationSettings.Count; i++)
{
lstStops.Items.Add(IsolatedStorageSettings.ApplicationSettings["stopNumber"] as string);
}
}
base.OnNavigatedTo(e);
}
Is this because on the favourites page, some other instance of IsolatedStorage
is being declared which doesn't contain any data? How do I access the data that was saved to IsolatedStorage
on the search page, and iterate through it to find all the information?