Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WPF WinForm
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 21:59pm
Comments
Sergey Alexandrovich Kryukov at 27-Nov-12 3:26am
   
Why? why?!
--SA

1 solution

Rate this: bad
good
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:
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
  Permalink  
Comments
εїзεїзεїз at 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 at 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)

  Print Answers RSS
0 OriginalGriff 499
1 Maciej Los 325
2 Sergey Alexandrovich Kryukov 234
3 DamithSL 233
4 Mathew Soji 195
0 OriginalGriff 7,168
1 Sergey Alexandrovich Kryukov 6,377
2 DamithSL 5,461
3 Manas Bhardwaj 4,876
4 Maciej Los 4,450


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 27 Nov 2012
Copyright © CodeProject, 1999-2014
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