1: class EventTriggeredManager:WeakEventManager
2: {
3: protected override void StartListening(object source)
4: {
5: EventSource src = source as EventSource;
6: Debug.Assert(src != null);
7: src.EventTriggered += new EventHandler(OnEventTriggered);
8: }
9: protected override void StopListening(object source)
10: {
11: EventSource src = source as EventSource;
12: Debug.Assert(src != null);
13: src.EventTriggered -= new EventHandler(OnEventTriggered);
14: }
15:
16: public static void AddListener(EventSource source, IWeakEventListener listener)
17: {
18: EventTriggeredManager.CurrentManager.ProtectedAddListener(source, listener);
19: }
20: public static void RemoveListener(EventSource source, IWeakEventListener listener)
21: {
22: EventTriggeredManager.CurrentManager.ProtectedRemoveListener(source, listener);
23: }
24:
25: void OnEventTriggered(object sender, EventArgs e)
26: {
27: base.DeliverEvent(sender, e);
28: }
29:
30: private static EventTriggeredManager CurrentManager
31: {
32: get
33: {
34: Type type = typeof(EventTriggeredManager);
35: EventTriggeredManager manager = (EventTriggeredManager)WeakEventManager.GetCurrentManager(type);
36: if (manager == null)
37: {
38: manager = new EventTriggeredManager();
39: WeakEventManager.SetCurrentManager(type, manager);
40: }
41: return manager;
42: }
43: }
44: }