Click here to Skip to main content
13,141,838 members (61,410 online)
Rate this:
Please Sign up or sign in to 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 26-Nov-12 20:59pm
Why? why?!

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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:[^],[^].

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.

εїзεїзεїз 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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170915.1 | Last Updated 27 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100