Windows Phone 7 Listbox not updating

VobiaGoTpab

New Member
I'm pulling in an XML file from the internet and loading it on the phone. Everything is going correctly, minus the listbox not updating on the initial load of the application. The simple path for the application is as follows:On the application load, it runs the update contacts method if it has connection to the internet. If it doesn't, it checks if it is the first load, if it is, it informs the user to connect to a mobile or wireless network before running the application, otherwise it loads old data.In the update method, it checks a webservice to see if there has been any updates since the last update. If its the first load, it says there has been 2000 updates, forcing an update. If the update number is greater than zero, it runs the download and then loads the data(this is the issue here), otherwise it loads the old data(the current data). The issue is after the download, it won't load the data. Here is the code for said items.The getData function:\[code\]private void getData() { try { using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) { IsolatedStorageFileStream isoFileStream = myIsolatedStorage.OpenFile("contacts.xml", FileMode.Open); using (StreamReader reader = new StreamReader(isoFileStream)) { XElement xmlContact = XElement.Parse(reader.ReadToEnd()); lstContacts.ItemsSource = from contact in xmlContact.Descendants("contact") select new ContactItem { ImageSource = contact.Element("Image").Value, FName = contact.Element("FName").Value, LName = contact.Element("LName").Value, Extension = contact.Element("Extension").Value, Email = contact.Element("Email").Value, Cell = contact.Element("Cell").Value, Title = contact.Element("TitleName").Value, Dept = contact.Element("deptName").Value, Office = contact.Element("officename").Value, ID = contact.Element("ID").Value }; } } } catch { } }\[/code\]the update function:\[code\]void contact_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { if (e.Error != null) { return; } XElement xmlContact = XElement.Parse(e.Result); string updates = xmlContact.Element("updates").Element("number").Value; if (firstrun) { updates = "2000"; settings["firstRun"] = (bool)false; } MessageBox.Show(updates); if (Convert.ToInt32(updates) > 0) { MessageBox.Show("Updating Contacts"); ContactReader cr = new ContactReader("http://domain.tld/RLContactApp/getContactsWP7.php?sqlQueryType=C&lastUpdated=01%2F01%2F2000&format=xml", "contacts.xml"); bool downloaded = cr.Download(); if (downloaded) { getData(); } } else { MessageBox.Show("Not Updating Contacts"); getData(); } }\[/code\]I'm looking for a way to make the data get loaded into the Listbox without telling the user to close the app and reload it.Any help is greatly appreciated.
 
Back
Top