You could subclass the ObservableCollection and override the OnCollectionChanged and OnPropertyChanged methods to marshall the event back to the UI thread using the correspending Dispatcher.
public class DispatcherObservableCollection<T> : ObservableCollection<T>
{
Dispatcher _dispatcher;
public DispatcherObservableCollection(Dispatcher dispatcher)
{
if (dispatcher == null)
throw new ArgumentNullException("dispatcher");
_dispatcher = dispatcher;
}
protected override void OnPropertyChanged(PropertyChangedEventArgs e)
{
if (!_dispatcher.CheckAccess())
{
_dispatcher.Invoke(
new Action<PropertyChangedEventArgs>(base.OnPropertyChanged), e);
}
else
{
base.OnPropertyChanged(e);
}
}
protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
{
if (!_dispatcher.CheckAccess())
{
_dispatcher.Invoke(
new Action<NotifyCollectionChangedEventArgs>(base.OnCollectionChanged), e);
}
else
{
base.OnCollectionChanged(e);
}
}
}