C# ';WindowsFormsHost';找不到

C# ';WindowsFormsHost';找不到,c#,wpf,C#,Wpf,在我的wpf应用程序中,我尝试使用windows窗体控件。。。。但我得到了一个错误,即 错误:找不到类型“WindowsFormsHost”。验证是否缺少部件引用,以及是否已生成所有引用的部件。 谁能帮我把它做完。。。下面是我的代码 c#:code public Window2() { InitializeComponent(); System.Windows.Forms.PictureBox PictureBox1 = new

在我的wpf应用程序中,我尝试使用windows窗体控件。。。。但我得到了一个错误,即 错误:找不到类型“WindowsFormsHost”。验证是否缺少部件引用,以及是否已生成所有引用的部件。 谁能帮我把它做完。。。下面是我的代码

       c#:code

     public Window2()
    {
        InitializeComponent();
        System.Windows.Forms.PictureBox PictureBox1 = new System.Windows.Forms.PictureBox();
        windowsFormsHost1.Child = PictureBox1;
        PictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(PictureBox1_Paint);


    }
   xaml:code


         <WindowsFormsHost Height="175" HorizontalAlignment="Left" Margin="10,10,0,0" Name="windowsFormsHost1" VerticalAlignment="Top" Width="255" />
c#:代码
公共窗口2()
{
初始化组件();
System.Windows.Forms.PictureBox PictureBox1=新的System.Windows.Forms.PictureBox();
windowsFormsHost1.Child=PictureBox1;
PictureBox1.Paint+=新系统.Windows.Forms.PaintEventHandler(PictureBox1\u Paint);
}
xaml:代码

当我们看到一个错误时,通常会说:

找不到类型
SomeClass
。验证是否缺少部件引用,以及是否已生成所有引用的部件

可能会有一些问题。这意味着我们没有将相关dll的引用添加到项目中,或者我们没有正确导入名称空间

为了找到需要添加引用的dll,我们通常会转到MSDN,使用搜索词“
SomeClass
class”。。。在您的案例中,“
WindowsFormsHost
class”。对
WindowsFormsHost
类执行此操作时,我们看到:

注意下面这行:

程序集:WindowsFormsIntegration(在WindowsFormsIntegration.dll中)

查看Visual Studio中的“添加引用”对话框,我们可以看到
WindowsFormsIntegration
的dll条目:

这就是我们如何找到要导入的dll的方法。现在,我们只需要确保正确导入名称空间,或者使用C#:

在XAML中,在使用
WindowsFormsHost
控件之前,不需要为
WindowsFormsIntegration
dll添加XML命名空间

<WindowsFormsHost>
    <!-- Some WinForms Control -->
</WindowsFormsHost>


有关详细信息,请参阅MSDN上的
WindowsFormsHost
Class页面。

您确定已包含此
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation“
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml"
ya我添加了这些引用…您是否使用了
WindowsFormsIntegration
ref?否。如何添加此引用?是否应将此WindowsFormsIntegration.dll添加到我的应用程序中?
<WindowsFormsHost>
    <!-- Some WinForms Control -->
</WindowsFormsHost>