在WPF应用程序中,我创建了WindowsFormsHost
,并想在其中插入包含Form
/ COM
控件的Activex
。但是然后我得到:
A first chance exception of type 'System.ArgumentException' occurred in WindowsFormsIntegration.dll
at System.Windows.Forms.Integration.WindowsFormsHost.set_Child(Control value)
at HomeSecurity.MainWindow..ctor() w c:\Users\R\Documents\Visual Studio 2013\Projects\HomeSecurity\HomeSecurity\MainWindow.xaml.cs:row 26
'HomeSecurity.vshost.exe' (CLR v4.0.30319: HomeSecurity.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\UIAutomationTypes\v4.0_4.0.0.0__31bf3856ad364e35\UIAutomationTypes.dll'. Symbols loaded.
这是
MainWindow
的构造函数。类VideoStream
扩展了类Form
public MainWindow() {
InitializeComponent();
VideoStream VideoStream = new VideoStream();//creating a Form containing Activex control
WindowsFormsHost Host = new WindowsFormsHost();//creating a host
try {
Host.Child = VideoStream;//setting content of Host, CAUSES THE EXCEPTION PRINTED ABOVE
}catch(Exception e){
Console.WriteLine(e.StackTrace);//output above
}
}
我不能长时间处理它,也没有时间了。如何解决这个问题?
最佳答案
好吧,您不能在其中添加Form
(TopLevelControl)。您必须先使其成为子控件。将TopLevel
设置为false应该可以使它工作。
VideoStream.TopLevel = false;
注意:不仅对于
WindowsFormsHost
,即使对于Winforms应用程序,也不能在Form
内添加Form
,除非TopLevel
设置为false。关于c# - 在WindowsFormsHost中插入表单时出现ArgumentException,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20925966/