使用Windows窗体主机在WPF中嵌入SWF文件? [英] Embedding SWF file in WPF using Windows Forms Host?
问题描述
我目前需要在我的WPF表单中嵌入一个SWF文件。我读过它,至少有两种方法可以实现这一点:
- 将SWF嵌入到HTML文件中,并将后者嵌入到我的form。
- 使用AxShockwaveFlashObjects程序集嵌入SWF。因为这是为了在WinForms中使用,而不是在WPF中使用,所以我将不得不使用Windows窗体主机,并将Shockwave Flash Object放入其中。
由于我的应用程序的一些要求(基本上是shockwave对象的GetVariable函数),我选择了第二个选项。我把Windows窗体主机放在我的WPF窗体中,并将下面的代码放在它的构造函数中:
pre $ 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>
但是,当我调试代码,我得到这个错误启动: p>
'类型'Flash_in_WPF.MainWindow'中与指定绑定约束匹配的构造函数的调用引发了一个异常'行号'4'和
如果我移动该代码以在单击按钮时运行,则会得到不同的错误消息: / b>
引发类型为System.Windows.Forms.AxHost + InvalidActiveXStateException的异常。
为什么我会收到这些错误?
编辑:解决了!将整个初始化代码移动到Grid_Loaded事件而不是在我的ctor。
预先感谢
解决它!我想应该把问题设置为已解决。
原来我需要将整个初始化代码移到Grid_Loaded事件中,而不是在我的ctor中。
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
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.
这篇关于使用Windows窗体主机在WPF中嵌入SWF文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!