Are there any potential issues with updating UI bound properties of the ViewModel from the Backgroundworker? I am trying to update the VM while it is bound to the UI, and potentially users might be typing in.. how does the the synchronization work here (I don’t think I can use Lock statements from XAML).
Thanks in advance..
When updating scalar properties, you don’t need to worry about doing it on the UI thread. The
PropertyChangedevent is automatically marshalled to the UI thread.However, it won’t work for collections that implement
INotifyCollectionChanged. TheCollectionChangedevent won’t be marshalled to the UI thread, and it will cause an exception. So if you modify a collection that is bound to anItemsControl, you need to useDispatcher.Invoke(or another synchronization mechanism) to do it on the UI thread. Another option is to use a specialized collection that takes care of marshalling the event to the correct thread. See this article for an example of such a collection.