3

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:

  • Embedding the SWF inside an HTML file and embed the latter in my form.
  • 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.

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:

    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;
    }

But when I debug the code, I get this error on startup:

'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'.

If I move that code to run when a button is clicked, I get a different error message:

Exception of type 'System.Windows.Forms.AxHost+InvalidActiveXStateException' was thrown.

Why am I getting these errors?

Edit: solved it! turns out I needed to move the whole initialization code to the "Grid_Loaded" event instead of in my ctor.

Thanks in advance

Itamar Marom
  • 525
  • 8
  • 21
  • Hi, I'm also trying to solve this problem; could you elaborate on how you solved it? – debu Oct 02 '13 at 15:36
  • I'm sorry, but I can' t say I remember after two years. It seems I cut the code you see here in `MainWindow()` (except the `InitializeComponent()` invocation) and moved it somewhere else. Can you further explain what you are doing and what happens when you try what I tried? – Itamar Marom Oct 06 '13 at 04:24

1 Answers1

1

Solved it! Figured I should set the question as solved.

Turns out I needed to move the whole initialization code to the "Grid_Loaded" event instead of in my ctor.

Itamar Marom
  • 525
  • 8
  • 21