开发者

is it possible to use Winform components in WPF

开发者 https://www.devze.com 2023-01-09 11:58 出处:网络
We have a product which is developed using W开发者_Python百科informs - .net 2.0. Now we are thinking about migrating this application to WPF. Is is possible to use the same Winform components in WPF.

We have a product which is developed using W开发者_Python百科informs - .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.


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.


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消