我目前需要在我的 WPF 表单中嵌入一个 SWF 文件。我读过它,至少有两种方法可以做到这一点:
由于我的应用程序的一些要求(基本上是冲击波对象的“GetVariable”函数),我选择了第二个选项。我在 WPF 表单中放置了一个 Windows 窗体主机,并将以下代码放入其构造函数中:
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;
}
但是当我调试代码时,我在启动时收到此错误:
'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'.
如果我在单击按钮时移动该代码以运行,我会收到不同的错误消息:
Exception of type 'System.Windows.Forms.AxHost+InvalidActiveXStateException' was thrown.
为什么我会收到这些错误?
编辑:解决了! 原来我需要将整个初始化代码移动到“Grid_Loaded”事件而不是我的ctor中。
提前致谢
最佳答案
解决了 !认为我应该将问题设置为已解决。
结果我需要将整个初始化代码移动到“Grid_Loaded”事件而不是我的ctor中。
关于wpf - 使用 Windows 窗体主机在 WPF 中嵌入 SWF 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7111165/