1、添加两个引用:WindowsFormsIntegration.dll(负责整合WPF和Windows)、System.Windows.Forms.
2、在 XAML文件中添加两个引用(粗体部分):
<Window x:Class="CrossBowDemo.MainWindow" xmlns:wfi ="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration" xmlns:wf ="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Hosting Windows Forms Control In WPF" Height="300" Width="650" ResizeMode="NoResize" Loaded="WindowLoadedHandler"> </Window>
3、在XAML添加控件:
<WindowsFormsHost Name="windowsFormsHost" Margin="0" Background="#FF323E34"> <wf:PictureBox Name="mainBox" Paint="PictureBox_Paint"></wf:PictureBox> </WindowsFormsHost>