Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
A collection of WinForms are available in Windowsform Project.
I have created WPF application and wants to Open Winform.

What I have tried:

A WindowsForm Project which contains winforms.
A WPF Application for Accessing winforms from above project.

WindowsFormHost provides the facility to access only winforms controls. But I want to access to Winforms.
Posted
Updated 29-Oct-20 0:54am
Comments
Richard MacCutchan 29-Oct-20 6:38am    
What is the problem?
DoingWork 29-Oct-20 6:52am    
I can Open Wpf Window by this C# code.
var wpfwindow = new WpfApp.MainWindow();
ElementHost.EnableModelessKeyboardInterop(wpfwindow);
wpfwindow.Show();

My Problem:
Now Vice-Versa, I want to open Winform from WPF Project and problem is that I am failed. ANY HELP PLEASE.
DoingWork 29-Oct-20 7:27am    
I have Tried this Code snipped. Nither form display nor any Exception.
WindowsFormsHost wfhost = new WindowsFormsHost();
WinformClassLib.Winform winform = new WinformClassLib.Winform();
winform.TopLevel = false;
wfhost.Child = winform;
wfhost.Child.Show();

1 solution

You would need to use WindowsFormsHost control for it.

Following Microsoft document will help you guide:
Host a Windows Forms control in WPF | Microsoft Docs[^]
Walkthrough: Hosting a WPF Composite Control in Windows Forms[^]
 
Share this answer
 
Comments
DoingWork 29-Oct-20 7:27am    
I have Tried this Code snipped. Nither form display nor any Exception.
WindowsFormsHost wfhost = new WindowsFormsHost();
WinformClassLib.Winform winform = new WinformClassLib.Winform();
winform.TopLevel = false;
wfhost.Child = winform;
wfhost.Child.Show();
Sandeep Mewara 29-Oct-20 10:08am    
Did you look at: https://github.com/Microsoft/WPF-Samples/tree/master/Migration%20and%20Interoperability/HostingWfInWPF

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