Hosting Windows Forms Controls in WPF
- Create a WPF project.
- Add references to required assemblies:
WindowsFormsIntegrations
System.Windows.Forms
System.Windows.Forms.DataVisualization
- Add namespace in XAML:
<Window ... xmlns:winforms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" xmlns:charting="clr-namespace:System.Windows.Forms.DataVisualization.Charting;assembly=System.Windows.Forms.DataVisualization" Title="MainWindow" Height="350" Width="525" > ...
- Add
WindowsFormsHost
tag inside a grid element (in XAML), then place the required Windows Form control inside it (eg. an MS Chart control):<Grid> <WindowsFormsHost> <charting:Chart x:Name="chart1"/> </WindowsFormsHost> </Grid>