简体   繁体   中英

Calling WPF Control Library

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM