views:

39

answers:

1

Hi all,

When I want to show user a (windows) form which resides in a DLL (in this case Form1), I use the following code from another executable;

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

Now, I created another DLL using WPF. When I use the above code, I got the following error;

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

So, How can I cast System.Windows.Window to System.Windows.Forms.Form? Or, how can I show the window which resides in a WPF-created-DLL from c# forms app?

+1  A: 

You cannot directly cast a System.Windows.Window to System.Windows.Forms.Form.

However, it is possible to create a windows form and use it to host a WPF control as a child control.

Windows Forms provides the ElementHost control for this.

Andrew Shepherd
Thanks. I was looking for this answer.
Uygar Y