Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Windows;
|
---|
6 |
|
---|
7 | namespace Microsoft.Research.DynamicDataDisplay.Common
|
---|
8 | {
|
---|
9 | public sealed class PlotterEventHelper
|
---|
10 | {
|
---|
11 | private RoutedEvent @event;
|
---|
12 | internal PlotterEventHelper(RoutedEvent @event)
|
---|
13 | {
|
---|
14 | this.@event = @event;
|
---|
15 | }
|
---|
16 |
|
---|
17 | // todo use a weakReference here
|
---|
18 | private readonly Dictionary<DependencyObject, EventHandler<PlotterChangedEventArgs>> handlers = new Dictionary<DependencyObject, EventHandler<PlotterChangedEventArgs>>();
|
---|
19 |
|
---|
20 | public void Subscribe(DependencyObject target, EventHandler<PlotterChangedEventArgs> handler)
|
---|
21 | {
|
---|
22 | if (target == null)
|
---|
23 | throw new ArgumentNullException("target");
|
---|
24 | if (handler == null)
|
---|
25 | throw new ArgumentNullException("handler");
|
---|
26 |
|
---|
27 | handlers.Add(target, handler);
|
---|
28 | }
|
---|
29 |
|
---|
30 | internal void Notify(FrameworkElement target, PlotterChangedEventArgs args)
|
---|
31 | {
|
---|
32 | if (args.RoutedEvent == @event && handlers.ContainsKey(target))
|
---|
33 | {
|
---|
34 | var handler = handlers[target];
|
---|
35 | handler(target, args);
|
---|
36 | }
|
---|
37 | }
|
---|
38 | }
|
---|
39 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.