質問

My Main Project Is Under WPF, In My Solution I have:

  1. winform which name is Form1
  2. wpfForm which name is MainWindow.xaml

I want to do this job: if button clicked, I show the Form1 in MainWindow Exactly Like MDI

役に立ちましたか?

解決

Thanks for helping me in this case,your answers really help me but i found my aim : i just wanted to use windows form (form1) in to wpf windows (not my windows form controls ) in my form code,i just change the inheritance of form1 to Usercontrol instead of Form like this

public partial class Form1: UserControl
{
  /// my code ...
}

therefor i can use this usercontrol in my windosformshost because my form is usercontrol now(nice job) but i got another problem , my controls didn't have visual sytle , cause of that i search in msdn , i got the answer from this link visual_Problem and the answer was in enable_visual i mean , before the winformshot host my windows form(ofcource my usercontrol) i should write this code :

System.Windows.Forms.Application.EnableVisualStyles();

Thanks for your comments. Best Regards, Hothreeyn.

他のヒント

from MSDN: WindowsFormsHost Class

Use the WindowsFormsHost element to place a Windows Forms control within your WPF element or page.

To host a WPF element in a Windows Forms control or form, use the ElementHost control.

To host a Windows Forms control in a WPF element, you must assign the Windows Forms control to the Child property.

I think you should handle the MDI layout in WPF and then inside the WPF child windows you put the WindowsFormsHost control and once you created the windows forms control you assign it as child of the WindowsFormsHost.

Refer to the MSDN Documentation for the WindowsFormsHost control in WPF. There is an example at the bottom of the documentation to show how it can be used to integrate WinForms control into WPF. All you will need to do is change the MaskedTextBox to your control: Form1.

As I understand it, you can't get an entire WinForm to interoperate with WPF. You can place WinForm controls on WPF surfaces via the WindowsFormHost, but not a form.

If you can package all of the contents of your WinForm Form into a WinForm UserControl, than you should be able to pull this off.

Using WindowsFormHost control, you can use a Windows Forms control in WPF. you can refer this link.

WPF has no native support for MDI, you can use this wpfmdi.codeplex.com or more complex this one chronoswpf.codeplex.com

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top