Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Thanks in Advance,

Tool: Visual Studio 2010/2012

I have created a Diagram in WPF as a User control, I am using this control on Winform
as a hosted element using ElementHost control.

My Question is there any way i can load my winforms from this WPF control.Let say on
First link (button) of User Control open Form1 and on second link (button) of User Control open Form2.
When I am adding Project reference then it says "Reference would cause a circular dependency".


Any advice.
Posted
Comments
Sergey Alexandrovich Kryukov 27-Nov-12 3:26am    
Why? why?!
--SA

1 solution

The problem is not related to the interoperability between WPF and System.Windows.Forms. This problem is very complex, and the problem with circular dependencies is very simple. You should just avoid circular references between assemblies. You can have a separate assembly referenced by other two. As you did not show your code, that's all one can tell you.

As to the loading a form from WPF application, this is generally impossible. It's the best to avoid mixing WPF and Forms. Interoperability does exist, but it is designed to host a Forms control in WPF UI or a WPF control in Forms UI:
http://msdn.microsoft.com/en-us/library/ms751761.aspx[^],
http://msdn.microsoft.com/en-us/library/ms742215.aspx[^].

You cannot host a form, but you can do the following: put all content of a form into a panel and host this panel; but better design some control (possibly UserControl) to better fit the WPF design.

There is also an esoteric and very little known possibility to run two different UIs in two different threads of the same process, but it hardly be good enough, because communication between the two would be extremely limited.

Overall, avoiding to mix WPF and Forms in one process would be the very best thing.

—SA
 
Share this answer
 
Comments
εїзεїзεїз 27-Nov-12 3:45am    
Because if we will do the whole application in WPF , it would be a huge investment again. I had gone through MSDN but .......
Sergey Alexandrovich Kryukov 27-Nov-12 10:42am    
I can understand that. Still, things are as I described them. I didn't say you should never do the interop; after all, the interop was designed to cover situations like yours.
And I suggested you some pretty reasonable work-around in the statement "you can do the folloing...", it will certainly work. Give it a try and ask follow-up questions if you need.
If you agree it's reasonable, please accept the answer formally (green button)... -- thanks.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900