I think this is trivial, but I cannot find the answer 🙁
I have a WP7 page that hosts some controls that I want to populate with date read from a web request.
The web request is done with:
WebClient wr = new WebClient();
wr.DownloadStringCompleted += new DownloadStringCompletedEventHandler(Event_DownloadStringCompleted);
wr.DownloadStringAsync(new Uri(theURL));
and this is called in the Page_Loaded event.
In Event_DownloadStringCompleted I try to assign the new values to the TextBlocks, that completely ignore this command.
What am I doing wrong? Do I need to find a different event to launch the web request? Or is it possible to “refresh” the page after the web request is completed?
Thanks
Your Event_DownloadStringCompleted is not called on the UI thread so it can’t update the UI. Use the Dispatcher to get called back on the right thread. e.g.
page.Dispatcher.BeginInvoke(delegate() { textBlock.Text = “done!”; });