title: Handle Routed Events in WPF user control loaded from a dll at runtime
body: <p>I have an WPF control library, I successfully load its assembly from main app and show the user control I want. The problem is that I want to handle keyboard routed event for usercontrol but it seems that the message never reach to it. Advice?:</p>
  
  <p>My scenario
  Main App Window xaml:</p>
  
  <pre><code>&lt;Window x:Class="Apollo.Clock.UI.ClockWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
           ResizeMode="NoResize" WindowState="Maximized"&gt;
      &lt;Grid&gt;     
          &lt;StackPanel x:Name="MainContainer"&gt;&lt;/StackPanel&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>Loading user control from main app windows:</p>
  
  <pre><code>UserControl myControl = null;
  Assembly asm = Assembly.LoadFrom("AppUI.WPF.dll");
  Type[] tlist = asm.GetTypes();
  foreach (Type t in tlist){
      if (t.FullName == "DefaultSkin"){
          myControl = Activator.CreateInstance(t) as UserControl;
          MainContainer.Children.Add(myControl);
          break;
      }
  }
  </code></pre>
  
  <p>DefaultSkin xaml:</p>
  
  <pre><code>&lt;UserControl x:Class="DefaultSkin"
  Keyboard.PreviewKeyDown="Window_PreviewKeyDown"&gt;
  </code></pre>
  
  <p>DefaultSkin.cs</p>
  
  <pre><code>private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
  {
              e.Handled = true;
              //more code
  }
  </code></pre>