我有一个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将被正确加载。但是,如果我将项目引用添加到作为Windows窗体项目的项目中,则currentControl将获取正确的值。 我不想引用我不需要的WindowsForms项目。 任何人都有任何关于它为何如此工作以及如何解决它的建议? 我正在使用.Net 4.0。
答案 0 :(得分:0)
发现真正的问题。问题不在于我在编写问题时想到了对Windows Forms项目的引用。 真正的问题是我试图加载的Windows窗体控件无法找到它所需的dll。