title: Embedding SWF file in WPF using Windows Forms Host?
body: <p>I'm currently in need of embedding an SWF file inside my WPF form. I read about it and there are at least two ways to accomplish this:</p>
  
  <ul>
  <li>Embedding the SWF inside an HTML file and embed the latter in my form.</li>
  <li>Embedding the SWF using the "AxShockwaveFlashObjects" assemblies. since this is meant to be used in WinForms and not in WPF, I will have to use a Windows Forms Host and put the Shockwave Flash Object inside of it.</li>
  </ul>
  
  <p>Because of some of the requirements of my application (basically the "GetVariable" function of the shockwave object) I chose the second option. I put a Windows Forms Host in my WPF form, and put the following code in its constructor:</p>
  
  <pre><code>    public MainWindow()
      {
          InitializeComponent();
  
          AxShockwaveFlash flash = new AxShockwaveFlash();
  
          flash.Location = new System.Drawing.Point(0, 0);
          flash.Size = new System.Drawing.Size(200, 200);
          flash.Enabled = true;
          flash.Movie = "http://www.example.com/file.swf";
  
          windowsFormsHost1.Child = flash;
      }
  </code></pre>
  
  <p>But when I debug the code, I get this error on startup:</p>
  
  <blockquote>
    <p>'The invocation of the constructor on type 'Flash_in_WPF.MainWindow' that matches the specified binding constraints threw an exception.' Line number '4' and line position '106'.</p>
  </blockquote>
  
  <p>If I move that code to run when a button is clicked, I get a different error message:</p>
  
  <blockquote>
    <p>Exception of type 'System.Windows.Forms.AxHost+InvalidActiveXStateException' was thrown.</p>
  </blockquote>
  
  <p>Why am I getting these errors?</p>
  
  <p><strong>Edit: solved it!</strong> turns out I needed to move the whole initialization code to the "Grid_Loaded" event instead of in my ctor.</p>
  
  <p>Thanks in advance</p>