收集物品的事件

编程入门 行业动态 更新时间:2024-10-24 20:11:58
本文介绍了收集物品的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个自定义集合对象,可在添加,删除和修改项目时触发事件. 我想做的是每次添加一个项目时,我的集合对象都会发现该项目的事件,并为找到的每个事件创建侦听器. 这样,收集对象可以侦听其包含的每个项目的事件.如果集合中的某个项目触发了一个事件,则该集合可以触发其自己的事件以将该项目的事件冒泡. 换句话说,我有包含包含集合的集合的集合,并且我想将事件从较低的集合向上传递到较高的集合,直到到达最上层父对象为止. 什么是这样做的好方法? < 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.

更多推荐

收集物品的事件

本文发布于:2023-11-30 01:15:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648227.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:物品   事件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!