Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/Common/PlotterEventHelper.cs @ 13792

Last change on this file since 13792 was 12503, checked in by aballeit, 9 years ago

#2283 added GUI and charts; fixed MCTS

File size: 1.1 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Windows;
6
7namespace 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.