Live Chat Icon For mobile
Live Chat Icon

WPF FAQ - Windows Forms and WPF

Find answers for the most frequently asked questions
Expand All Collapse All

It can be done with the following code :

[XAML]

<Window x:Class='HostingWfInWpf.Window1'
    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'  
    Title='HostingWfInWpf'
    >
    <Grid>
        <WindowsFormsHost>
            <wf:MaskedTextBox x:Name='mtbDate' Mask='00/00/0000'/>
        </WindowsFormsHost>
    </Grid>  
</Window>

Permalink

The System.Windows.Forms.Integration namespace is defined in ‘WindowsFormsIntegration.dll’ which currently ships in the WinFX SDK, not in the standard redist. Therefore, the file will be found in ‘\Program Files\Reference Assemblies\Microsoft\Framework\v3.0’.

Permalink

Windows Forms user controls will work the same as the standard Windows Forms controls, which means you can certainly use them in WPF applications. As far as third-party controls go, it depends on how these controls are built. If they are built as managed Windows Forms custom controls, they will also work fine in this scenario. If they are built as ActiveX controls, they can also be used in a WPF application as long as they are contained within a WindowsFormsHost control. Since Windows Forms already has support for hosting ActiveX controls, all you need to do is generate the managed wrappers for the ActiveX control and then use those wrappers to instantiate the control and host it within the WindowsFormsHost control on a WPF window or page. One handy way to do this is to simply create a Windows Forms UserControl that contains the ActiveX control and then simply host the UserControl in the WindowsFormsHost control.

Permalink

Share with

Couldn't find the FAQs you're looking for?

Please submit your question and answer.