ObservableCollection清除异常。 [英] ObservableCollection clear exception.

查看:606
本文介绍了ObservableCollection清除异常。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我清除observable集合时,我得到一个异常,因为这种类型的CollectionView不支持从与Dispatcher线程不同的线程更改其SourceCollection。

解决方案

您可能正在尝试清除背景或其他线程上的集合。

您的UI需要通知刷新,因此这种情况只能在UI线程上发生。



试试这个 Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal,new Action(()=> _observableCollection.Clear());

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."

解决方案

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


这篇关于ObservableCollection清除异常。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆