C# 将OberservableCollection分配给ListBox并排除某些条目

C# 将OberservableCollection分配给ListBox并排除某些条目,c#,listbox,observablecollection,inheritance,C#,Listbox,Observablecollection,Inheritance,我从一个接口继承了不同的类,所有这些类都被添加到OberservableCollection中。有人能给我解释一下如何将Observablecollection的所有值分配给我的列表框,b类除外 假设(编辑): private void start() { DP=新的MyClass(); this.ListBox.ItemsSource=新的ObservableCollection(MyClass.Handler.Instances.OfType()); } ... 类处理程序():INotif

我从一个接口继承了不同的类,所有这些类都被添加到OberservableCollection中。有人能给我解释一下如何将Observablecollection的所有值分配给我的列表框,b类除外

假设(编辑):

private void start()
{
DP=新的MyClass();
this.ListBox.ItemsSource=新的ObservableCollection(MyClass.Handler.Instances.OfType());
}
...
类处理程序():INotifyPropertyChanged
{
公共可观测集合实例{get;private set;}
...
}
类HandlerItem:INotifyPropertyChanged
{
公共实例inst{get;private set;}//实例可以是WInstance或CInstance
}
在运行期间,MyClass从远程计算机接收WInstance或CInstance的一些对象。如果我试图用Instances.OfType()解决它,我的ItemsSource似乎不会被更新

var list=new list();
var list = new List<Instance>();

//.. add all items to your list here.


ObservableCollection<Instance> OCI = new ObservableCollection<Instance>(list.OfType<classa>());
// the above will generate a new ObservableCollection which contains all items of type classa from list.
//.. 在此处将所有项目添加到您的列表中。 ObservableCollection OCI=新的ObservableCollection(list.OfType()); //上面将生成一个新的ObservableCollection,其中包含列表中classa类型的所有项。
首先,谢谢您。我的observablecollection动态地获得了一些条目,所以我必须实施一个解决方案来获得当前值,不是吗?@ViktorZimmermann我不明白你所说的“动态地获得一些条目”是什么意思。请张贴您的密码。尽管如此,我的解决方案应该是可行的。
var list = new List<Instance>();

//.. add all items to your list here.


ObservableCollection<Instance> OCI = new ObservableCollection<Instance>(list.OfType<classa>());
// the above will generate a new ObservableCollection which contains all items of type classa from list.