Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When i clear the observable collection am getting an exception as "This type of CollectionView does not support changes to its SourceCollection from a thread different from the Dispatcher thread."
Posted

1 solution

You may be trying to clear the collection on background or another thread.
Your UI needs to be notified of a refresh and so this clear can only happen on the UI thread.

Try this Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => _observableCollection.Clear());
 
Share this answer
 
v2
Comments
Navya Sri 3-May-15 3:39am    
I have two datagrids when i am going to click on first datagrid row i should fill the 2nd grid with respective details. if i use the above dispatcher my data is not added to the 2nd grid.
Navya Sri 3-May-15 3:41am    
same exception is thrown when i add to observablecollection.
gunnalahariom 6-Sep-21 3:04am    
Thanks abhinav , it wrked for me, but i have to changes this every where while performing any modification to the collection.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900