0
votes

I am using the following code to host a WPF application inside my Windows Forms application:

var clientApplication = Process.Start("C:\\WpfApplication1.exe");

SetParent(clientApplication.MainWindowHandle, this.Handle);

The WPF app is opening as an independent app, how to force it to open withing the main windows form

1
Process.Start will always start a new process. Check this code project link for some clues to your problem codeproject.com/Articles/9123/… - Ravi Y
I don't know whether you want to host wpf control or not.If you want to host wpf control inside winforms application.Here is a link for that switchonthecode.com/tutorials/… - Sai
No I actually want to host a complete application - Hassan Mokdad

1 Answers

3
votes

A "complete application", if it is a desktop application includes at least 1 Window object, which cannot be hosted inside anything because it is a Window. What you will need to do is to remove any top level Windows from your WPF application and then you can host indivual Views (UserControls or other type of non-window elements) using an ElementHost.

Edit: Be aware that in order to do this, you have to either reference the WPF application project from your winforms project, or load everything in runtime via reflection. There's no way you can make a .Exe file be hosted inside another window.