using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; namespace Microsoft.Research.DynamicDataDisplay.Common { public sealed class PlotterEventHelper { private RoutedEvent @event; internal PlotterEventHelper(RoutedEvent @event) { this.@event = @event; } // todo use a weakReference here private readonly Dictionary> handlers = new Dictionary>(); public void Subscribe(DependencyObject target, EventHandler handler) { if (target == null) throw new ArgumentNullException("target"); if (handler == null) throw new ArgumentNullException("handler"); handlers.Add(target, handler); } internal void Notify(FrameworkElement target, PlotterChangedEventArgs args) { if (args.RoutedEvent == @event && handlers.ContainsKey(target)) { var handler = handlers[target]; handler(target, args); } } } }