开发者

wpf thread error

开发者 https://www.devze.com 2023-04-13 00:57 出处:网络
i have Observable collection object bounded to a treeView: MainTreeView.ItemsSource = ((App)Appl开发者_Python百科ication.Current).TucOC;

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

精彩评论

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

关注公众号