[英]Add dynamically loaded WindowsForms control to a WPF WindowsFormsHost
我有一个WPF项目,其中像这样动态加载WindowsForsm程序集(dll文件):
Assembly currentAssembly = Assembly.LoadFile(System.IO.Directory.GetCurrentDirectory() + @"\" + fileName);
System.Windows.Forms.Control currentControl = (System.Windows.Forms.Control)currentAssembly.CreateInstance(featureName, false);
featureHost.Child = currentControl;
我的FeatureHost的XAML代码如下所示:
<WindowsFormsHost Name="featureHost" Grid.Row="1" Margin="14,4,14,14" Background="WhiteSmoke"></WindowsFormsHost>
我的问题是在C#代码中currentControl将为null,但是currentAssembly seasm必须正确加载。 但是,如果我将项目引用添加到Windows窗体项目的项目中,则currentControl会获取正确的值。 当然,我不想引用我不需要的WindowsForms项目。 有人对它为什么如此工作以及如何解决有任何建议。 我正在使用.Net 4.0。
找到了真正的问题。 问题不在于我写问题时以为需要引用Windows Forms项目。 真正的问题是我尝试加载的Windows Forms控件找不到所需的dll。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.