title: ContextMenuOpening event not firing in WPF?
body: <p>I have a resource dictionary inside which I have a context menu:</p>
  
  <pre><code>&lt;ResourceDictionary x:Class="MyApp.Components.MyContextMenu"
                      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                      xmlns:local="clr-namespace:MyApp"
                      xmlns:components="clr-namespace:MyApp.Components"&gt;
      &lt;ContextMenu ContextMenuOpening="OnContextMenuOpening"&gt;
  </code></pre>
  
  <p>and the resource dictionary XAML has this code behind:</p>
  
  <pre><code>using System;
  using System.Windows;
  using System.Windows.Controls;
  
  namespace MyApp.Components
  {
      public partial class MyContextMenu : ResourceDictionary
      {
          public MyContextMenu()
          {
              InitializeComponent();
          }  
  
          void OnContextMenuOpening(object sender, ContextMenuEventArgs e)
          {
              Console.WriteLine("here i am!");
          }
      }
  }
  </code></pre>
  
  <p>The log is not appearing. I wonder why the event is not firing or getting to the right place -- is the problem because I have wrapped the context menu inside this resource dictionary?</p>
  
  <p><strong>Update:</strong> Interestingly if I remove the code-behind function, I get an error during compilation:</p>
  
  <blockquote>
    <p>does not contain a definition for 'ContextMenu_OnContextMenuOpening'
    and no extension method 'ContextMenu_OnContextMenuOpening' accepting a
    first argument of type 'MyApp.Components.MyContextMenu' could be found
    (are you missing a using directive or an assembly reference?)</p>
  </blockquote>
  
  <p><strong>Update 2:</strong> Looks like that both <code>Console.WriteLine</code> and <code>Debug.WriteLine</code> produce output, but only "randomly" and especially when I'm clicking near the bottom of the item. Some sort of collision detection not working maybe?</p>