我有一个带有嵌套ListBox的ListBox.两者都有ObservableCollections作为其ItemsSource设置,内部ListBox的集合是外部对象的成员...
这些集合由BackgroundWorker填充,后者从Web服务收集数据.我不得不从ObservableCollection更改为AsyncObservableCollection,以便能够从worker的代码中添加项目.AsyncObservableCollection代码来自这里:让工作线程更新绑定到ListCollectionView的ObservableCollection
我的问题是内部ListBox保持显示重复的项目.如果它决定复制它似乎总是重复第一个项目.我不知道为什么会这样.将事件监听器附加到集合的CollectionChanged事件后,我发现每个项目都会触发该事件一次.
你有什么想法?
谢谢,斯蒂芬
wpf asynchronous listbox observablecollection backgroundworker
我有一个包含特殊集合的泛型类.此集合的一个实例作为对象传递给方法.现在我必须调用泛型类的方法之一.我看到的问题是我不知道集合中的项目是哪种类型,所以我在使用该属性之前无法进行转换.
public class MyGenericCollection<T>: ReadOnlyObservableCollection<T>
{
public bool MyProperty
{
get
{
// do some stuff and return
}
}
}
public bool ProblematicMethod(object argument)
{
MyGenericCollection impossibleCast = (MyGenericCollection) argument;
return impossibleCast.MyProperty;
}
Run Code Online (Sandbox Code Playgroud)
有没有解决这个问题的方法?