I have created a View Model in Silverlight. This View Model h开发者_StackOverflowas an event defined as:
public event EventHandler Data_Loaded;
I want to "Raise" this event when data from a service call has been completed. This will allow my UI to respond properly. Please note, it is not just a simple binding scenario, that is why I want the event.
The service call is made via a HttpWebRequest. Once this request is done, I'm properly parsing the results. I'm trying to let the UI know that I'm done, but initially I was getting an error that said "Invalid cross-thread access". I spoke to a co-worker who told me I should use the SynchronizationContext.Current to raise an event. Unfortunately, I do not understand how to do this. Can someone please explain it to me?
You need to use the Dispatcher
to force the event to be raised on the UI thread.
Deployment.Current.Dispatcher.BeginInvoke(() => DataLoaded(this,EventArgs.Empty));
精彩评论