收集物品的事件 [英] Collections That Listen To It's Items Events

查看:73
本文介绍了收集物品的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个自定义集合对象,可在添加,删除和修改项目时触发事件.

我想做的是每次添加一个项目时,我的集合对象都会发现该项目的事件,并为找到的每个事件创建侦听器.

这样,收集对象可以侦听其包含的每个项目的事件.如果集合中的某个项目触发了一个事件,则该集合可以触发其自己的事件以将该项目的事件冒泡.

换句话说,我有包含包含集合的集合的集合,并且我想将事件从较低的集合向上传递到较高的集合,直到到达最上层父对象为止.

什么是这样做的好方法?

< edit>我忘了提到我正在使用2.0,因此必须自己进行连接.

Hi,

I have a custom collection object that fires events when items are added, removed and modified.

What I would like to do is each time an item is added, my collection object will discover the events for that item and will create listeners for each event that it finds.

This way the collection object can listen to the events for each item it contains. If an item in the collection fires an event the collection can then fire its own event to bubble that item''s event up.

It other words I have collections that contains collections that contains collections and I want to pass events up from a lower collection up to a higher collection till it reaches the top most parent object.

What''s a good way to do this?

<edit>I forgot to mention that I am using 2.0 and so I have to wire this up myself.

推荐答案

听起来您正在创建 ObservableCollection [ WPF路由事件 [^ ]
It sounds like you are creating an ObservableCollection [^]and WPF Routed Events[^]


如果该事件是CollectionChanged事件中的添加事件,我会将事件添加到每个项目中(使用e 参数).

一旦这些事件触发,我要么将其传递给父级,要么按需要在此处进行处理.
If the event is an add event in CollectionChanged event, I would add my events to each item (using the e arguments).

Once these events fire, I would then either pass them onto the parent or handle them here - as required.


我忘了提到我正在使用2.0,因此必须将其连接起来我自己.
I forgot to mention that I am using 2.0 and so I have to wire this up myself.


这篇关于收集物品的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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