开发者

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)));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜