将集合绑定到具有不同类型的另一个集合 [英] Binding Collection to another Collection with different type
问题描述
好吧,我需要一些帮助来将一个集合绑定到另一个具有不同类型的集合
我有一个数据类(一个类,仅带有带有notifypropertychange的public get/set属性)
/>我有一个存储此数据对象的主集合
我有另一个集合(简称为集合A),但是此集合是数据类内部属性的集合
我可以将收藏夹A绑定到主收藏夹吗? master集合将用于重新排序和修改数据类的属性.
我是否使用转换器来做到这一点?还是还有其他内容?
问候
ok, i need some help on binding a collection to another collection with different type
i have a data class(a class with just public get/set properties with notifypropertychange)
i have a master collection that stores this data object
i have another collection(lets call it collection A), however this collection is a collection of a property inside the data class
how can i bind collection A to the master collection. the master collection will be used for reordering and modifying the data classes' properties.
do i use a converter to do that? or is there something else?
Regards
推荐答案
如果我理解你对吧,您要在集合A中列出的是某个属性对主集合中的任何对象具有的所有值的列表,对吧?
好吧,由于数据对象实现了INotifyPropertyChanged,因此您可以注册一个处理程序,只要您将一个项目添加到主集合中,就可以在每次添加,删除或所讨论的属性更改其值时更新集合A.但是,为了知道何时删除一个值,您要么必须检查master集合中的所有项目(尽管可以通过LINQ非常优雅地做到这一点),否则,如果这样做效率低下,则必须为每个告诉您何时可以将其从集合A中删除的值实现一个引用计数器.
Hi,
if I understand you right, what you want in Collection A is a list of all the values a certain property has on any object in your master collection, right?
Well, since the data objects implement INotifyPropertyChanged, you could register a handler for that whenever you add an item to the master collection, and update collection A whenever an item is added, removed, or the property in question changes its value. However, in order to know when to remove a value, you'd either have to check all items in the master collection (could do that through LINQ quite elegantly, though), or, if that is to inefficient, you'd have to implement a reference counter for each value that tells you when you can remove it from collection A.
这篇关于将集合绑定到具有不同类型的另一个集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!