2010-05-03 14 views
1

當我想向用戶展示一個駐留在DLL(本例中爲Form1)的窗體時,我使用下面的代碼從另一個可執行文件;調用WPF控件庫

Assembly a = Assembly.Load(System.IO.File.ReadAllBytes("mydll.dll")); 
Form MyDLLFormInstance = (Form)a.CreateInstance("myNamespace.Form1"); 
MyDLLFormInstance.Show(); 

現在,我創建了另一個使用WPF的DLL。當我使用上面的代碼時,我得到以下錯誤;

Unable to cast object of type 'myNamespace.Window1' to type 'System.Windows.Forms.Form'. 

那麼,我該如何將System.Windows.Window投射到System.Windows.Forms.Form?或者,我怎樣才能顯示窗口駐留在WPF創建的DLL從C#表單應用程序?

回答

1

您無法直接投射 System.Windows.Window System.Windows.Forms.Form

但是,可以創建一個Windows窗體並將其用作託管WPF控件作爲子控件。

Windows窗體爲此提供了ElementHost控件。

+0

謝謝。我正在尋找這個答案。 – 2010-05-03 12:08:38