Embedding SWF file in WPF using Windows Forms Host?

邮差的信 提交于 2019-12-07 13:41:44

问题


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


回答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.



来源:https://stackoverflow.com/questions/7111165/embedding-swf-file-in-wpf-using-windows-forms-host

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!