繁体   English   中英

找不到'WindowsFormsHost'

[英]'WindowsFormsHost' was not found

在我的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" />

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

找不到类型SomeClass 验证您是否缺少程序集引用,并且已构建所有引用的程序集

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

要找到我们需要添加引用的dll,我们通常会转到MSDN,使用搜索术语' SomeClass class'进行搜索...在您的情况下' WindowsFormsHost类'。 WindowsFormsHost类执行此操作,我们看到:

在此输入图像描述

请注意以下行:

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

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

在此输入图像描述

这就是我们如何找出要导入的DLL。 现在,我们只需要确保在C#中正确导入命名空间:

using System.Windows.Forms.Integration;

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM