I have worker class with
public event EventHandler<EventArgs> DataModified;
which can be raised from other than UI thread (it is network client which fetches updates from server).
I have ModelView with
ObservableCollection<DataModel> DataItems;
to which View binds. My modelview must subscribe to ModifiedEvent, so it can reflect changes in DataItems. How do I update DataItems from callback event? I do not have access to UI Dispatcher from my model view (because view should not be aware of modelview). What is proper .NET 4.5 way for handling this?
You can create a service wich holds a
CoreDispatcherand inject into your view model (or make it static)You should initialize SmartDispatcher in App.xaml.cs:
use it in this way:
This class is based on Jeff Wilcox’s analog for windows phone 7.