title: Attached event add handler method doesn't get called if it's defined in class library
body: <p>I use add[EventName]handler method to add a reference of the dependecy object to a singleton. In the following example there's a simple console output to demonstrate the problem.</p>
  
  <pre><code>public class Included
  {
      public static readonly RoutedEvent DummyEvent = EventManager.RegisterRoutedEvent("Included.DummyEvent", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(Included));
  
      public static void AddDummyHandler(DependencyObject d, RoutedEventHandler handler)
      {
          Console.WriteLine("-------------- included project dummy event handler");
          UIElement element = d as UIElement;
  
          if (element != null)
          {
              element.AddHandler(DummyEvent, handler);
          }
      }
  
      public static void RemoveDummyHandler(DependencyObject d, RoutedEventHandler handler)
      {
          UIElement element = d as UIElement;
          if (element != null)
          {
              element.RemoveHandler(DummyEvent, handler);
          }
      }
  }
  </code></pre>
  
  <p>This works when I include this class in to the project that I want to use. I use the attached event in the xaml like: </p>
  
  <pre><code>&lt;Button Name="MyButton" Width="200" Height="30" local:Included.Dummy="IncludedProject"&gt;IncludedToProject&lt;/Button&gt;
  </code></pre>
  
  <p>Which writes "-------------- included project dummy event handler" to the console when i run the app. </p>
  
  <p>The problem is when I use the same code in a class library, xaml doesn't trigger AddDummyHandler.</p>
  
  <pre><code>public class ExcludedClassLibrary
  {
  
      public static readonly RoutedEvent DummyEvent = EventManager.RegisterRoutedEvent("Excluded.DummyEvent", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(ExcludedClassLibrary));
  
      public static void AddDummyHandler(DependencyObject d, RoutedEventHandler handler)
      {
          Console.WriteLine("-------------- excluded project dummy event handler");
          UIElement element = d as UIElement;
  
          if (element != null)
          {
              element.AddHandler(DummyEvent, handler);
          }
      }
  
      public static void RemoveDummyHandler(DependencyObject d, RoutedEventHandler handler)
      {
          UIElement element = d as UIElement;
          if (element != null)
          {
              element.RemoveHandler(DummyEvent, handler);
          }
      }
  
  }
  </code></pre>
  
  <p>You can download and test the sample <a href="http://www.emrahozer.com/share/attachedeventtest.zip" rel="nofollow">project</a></p>