How to make winform work in WPF?

I want to use my winform on my wpf application - is this possible?

+2
source share
3 answers

Yes it is possible.

Use ElementHost to host WPF content in Windows Forms controls, and use WindowsFormsHost to host your Windows Forms component directly in a WPF control.

+4
source

Yes, WPF applications can contain WinForm controls and windows.

There is also a way to package WPF controls that WinForm will use, but it is much more involved and definitely not recommended.

Most books in WPF will tell you how to host WinForm controls.

+1
source

A small example showing the hosting of WinForms browser management (with shortcuts disabled) inside a WPF application:

<Window x:Class="how_to_make_winform_run_on_wpf.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" > <WindowsFormsHost> <wf:WebBrowser WebBrowserShortcutsEnabled="False" Url="http://stackoverflow.com"></wf:WebBrowser> </WindowsFormsHost> </Window> 

Of course, you should add links to WinFormsIntegration and System.Windows.Forms assemblies. When using this example, you will notice that all standard WinForms controls use a flat style. To enable WinXP styles for your WinForms controls, put

 public App() { System.Windows.Forms.Application.EnableVisualStyles(); } 

inside your app.xaml.cs

+1
source

Source: https://habr.com/ru/post/944067/


All Articles