Live update of listbox
I currently have a listbox which is fed by a XML file. I'm using a webclient to grab the XML and then using the following code to parse it into the listbox;
XElement xmlSearch = XElement.Parse(e.Result);
lstbSearch.ItemsSource = from Search in xmlSearch.Descendants("e2event")
select new GetSearch
{
e2eventtitle = Search.Element("e2eventtitle").Value,
开发者_开发技巧 e2eventid = Search.Element("e2eventid").Value
};
Now the file can be as big as 150kb, Which can take some time on a phone. So i was wondering if i could make it display in the listbox as the data is received. What's the best method to use whilst keeping good performance?
Many thanks, Nathan
The web client will not fire the completed event until all the data has been recieved so I will not be possible to view the data as it arrives.
In addition to @harryover's answer, using WebClient or HTTPWebRequest won't really allow you to do gradual rendering:
- For effective download of the data, the HTTP layer will hopefully use ZIP encoding - and partial zip files can't be unzipped
- Also, XML parsers are very poor at working with partial documents (they need open and close tags)
The best way to do what you want to do is probably to split your data up into separate HTTP requests - make lots of smaller requests instead of one big one.
精彩评论