title: Converting WPF application to UserControl for use in WinForms application via ElementHost
body: <p>I'm trying to convert <a href="http://www.codeproject.com/KB/WPF/WPFDiagramDesigner_Part4.aspx" rel="nofollow noreferrer">this WPF application</a> to WPF UserControl so I could use it in WinForms application via ElementHost. I'm new to WPF and have never even touched it prior to this attempt so I might be going about it completely the wrong way.</p>
  <p>I got the UserControl project to compile, however, my StaticResources get underlined in VS with message &quot;<em>The resource 'x' could not be resolved</em>&quot;. I've tried moving the xamls with the needed x:Key elements up one level (the same level as the UserControl Dijagram.xaml), but it still cannot resolve them.</p>
  <p>In the WinForms app, when trying to add the UserControl through designer by selecting hosted content in ElementHost tasks I get the following error:</p>
  <blockquote>
  <p>An error occured trying to create an object of type
  'DijagramLC.Dijagram'. Make sure the type has a default constructor.</p>
  </blockquote>
  <p>(even though default constructor exists).</p>
  <p>However, if I add it in codebehind, like this:</p>
  <pre><code>wpfUserControl = new Dijagram();
  elementHost1.Child = wpfUserControl;
  Controls.Add(elementHost1);
  </code></pre>
  <p>the code compiles but throws this runtime error: &quot;<em>System.Windows.Markup.XamlParseException: 'Provide value on 'System.Windows.StaticResourceExtension' threw an exception.' Line number '20' and line position '4'. ---&gt; System.Exception: Cannot find resource named 'MyToolbar'. Resource names are case sensitive.</em>&quot;</p>
  <p>I've tried with and without App.xaml and adding ResourceDictionary elements for problematic xamls, but basically, I have no idea what I'm doing :)</p>
  <p>I've uploaded the code to my SkyDrive and would really appreciate it if someone could take a look and tell me what I'm doing wrong:
  <a href="https://skydrive.live.com/redir.aspx?cid=21be1f8e850e85cc&amp;resid=21BE1F8E850E85CC!353" rel="nofollow noreferrer">https://skydrive.live.com/redir.aspx?cid=21be1f8e850e85cc&amp;resid=21BE1F8E850E85CC!353</a></p>
  <p>I hate jumping in blindly to new techonoly like this, but I have had no choice this time, and need to know if my requirement is even achievable this way.</p>