user640817
user640817

Reputation:

How to make winform run on WPF?

i want to use my winform on my wpf application - is it possible ?

Upvotes: 2

Views: 2810

Answers (3)

bsazonov
bsazonov

Reputation: 71

Little example showing hosting of WinForms Browser control (with disabled shortcuts) inside an 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 references to WinFormsIntegration and System.Windows.Forms assemblies. When using this sample you'll notice that all the standart WinForms controls use flat style. To enable WinXP-like styles for your WinForms controls, put

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

inside your App.xaml.cs

Upvotes: 1

Yanshof
Yanshof

Reputation: 9926

Yes - this is possible.

Use ElementHost to put WPF content into Windows Forms controls, And also to use WindowsFormsHost to host your Windows Forms component directly within a WPF element.

Upvotes: 4

Stephen Chung
Stephen Chung

Reputation: 14605

Yes, WPF applications can host WinForm controls and windows.

There is also a way to package WPF controls to be used in WinForm, but it is much more involved and definitely not recommended.

Most books on WPF will teach you how to host WinForm controls.

Upvotes: 1

Related Questions