I have a MainViewModel and a CategoryViewModel
MainViewmodel has the collection:
public ObservableCollection<Category> Categories { get; set; }
Inside CategoryViewModel I have the ICollectionView for filtering:
public ICollectionView CategoriesView { get; set; }
CategoriesView = CollectionViewSource.GetDefaultView(_mainViewModel.Categories );
CategoriesView .Filter = new Predicate<object>(o => Filter(o as Category));
The thing is that if I don't use CategoriesView I can modify (add, edit, remove) my Categories ObservableCollection, but when I implement the CategoriesView for filtering, I get a NotSupportedException when trying to add a new Category to the ObservableCollection:
This type of CollectionView does not support changes to its SourceCollection from a thread different from the Dispatcher thread
I already tried This type of CollectionView does not support changes to its SourceCollection from a thread different from the Dispatcher thread
App.Current.Dispatcher.Invoke((Action)delegate
{
_mainViewModel.Categories.Add(newCategory);
});
Also:
BindingOperations.EnableCollectionSynchronization(_matchObsCollection , _lock);
I already went to Debug --> Windows --> Threads The method is indeed in the Main Thread