views:

35

answers:

2

Hello All, We have a product which is developed using Winforms - .net 2.0. Now we are thinking about migrating this application to WPF. Is is possible to use the same Winform components in WPF.

Or if it is not possible, then which is best possible ways to Migrate this application to WPF.

Thanks and regards Harsha

+5  A: 

Yes. You can use ElementHost to put WPF content into Windows Forms controls, and WindowsFormsHost to host your Windows Forms component directly within a WPF element.

Reed Copsey
Thank you Reed.
Harsha
+1  A: 

There's a tutorial on Switch On The Code using the DataGridView.

You need to add references to System.Windows.Forms and WindowsFormsIntegration to get WindowsFormsHost.

You can do it in the XAML as well as the C# code:

<WindowsFormsHost Grid.Row="0">
  <WinForms:DataGridView x:Name="_MyDataGrid">
  </WinForms:DataGridView>
</WindowsFormsHost>

C#

 _MyHost = new WindowsFormsHost();
 _MyDataGrid = new System.Windows.Forms.DataGridView();

 ....

 _MyHost.Child = _MyDataGrid;
 _Container.Children.Add(_MyHost);
ChrisF
Thank you Chris. Thanks for the example also. Do you have any link to such projects/code sample.
Harsha
@Harsha - I don't know of any samples. Have you tried Code Project?
ChrisF
Ok Fine. I didn't search there. I will . . .Thanks for the direction.
Harsha