Nathan
Nathan

Reputation: 2513

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

Upvotes: 3

Views: 336

Answers (2)

harryovers
harryovers

Reputation: 3138

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.

Upvotes: 3

Stuart
Stuart

Reputation: 66882

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.

Upvotes: 2

Related Questions