[英]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.