views:

108

answers:

3

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

+1  A: 

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!"; });

John Vert
I understand the explanation, but I have some problem in implementing it - where do you think I should call BeginInvoke ? Right after having read the results I need to display? Or when? Thanks!
ila
well, I did implement the delegate callback, and I can see in debug that the code is executed, but no effect on the UI. when I navigate "back" using the pad at the bottom of the emulator I can see for a brief moment the correct values... I'm missing something :)
ila
A: 

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?

Andréas Saudemont
I tried to move the code in the OnNavigatedTo event, but I have the same results (as expected). The event is called, no errors.
ila
A: 

Hi Ila,

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.

Mick N