I think this is trivial, but 开发者_如何学CI 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!"; });
You might want to initiate the web request when the page's OnNavigatedTo() method is called, rather than when the page's Loaded event is fired, though I don't think this will solve your problem.
Are you sure that your handler of the DownloadStringCompleted event is called? If so, is the Error property of the DownloadStringCompletedEventArgs set to a non null value?
There are known display/refresh issues related to some display drivers introduced in the public beta. This has been known in some cases to be associated with ATI adapters. Some people report success following a driver update.
This may be affecting your refresh result.
Also you can check your driver is directx10 minimum and WDDM1.1 compliant per the WPDT system requirements. If not, driver upgrade (again), adapter change, or upgrade to Win7 if running Vista which has solved several obscure issues.
Also if you have the option, try running up your up on another PC with a different configuration.
精彩评论