wpf thread error
i have Observable collection object bounded to a treeView:
MainTreeView.ItemsSource = ((App)Appl开发者_Python百科ication.Current).TucOC;
the problem is that when i'm updating the ((App)Application.Current).TucOC this way:
_tucActivity.Add(new TucActivity(TucActivityEnum.Approve, null));
i get the following error: This type of CollectionView does not support changes to its SourceCollection from a thread different from the Dispatcher thread.
You can manipulate wpf objects only from UI thread. The error you get states you did it from a different thread. Simply get the Dispatcher from Application.Current, and call
_tucActivity.Add(new TucActivity(TucActivityEnum.Approve, null));
from it
Application.Current.Dispatcher.BeginInvoke(
DispatcherPriority.Normal, () => _tucActivity.Add(new TucActivity(TucActivityEnum.Approve, null)));
精彩评论