简体   繁体   English

在WPF的WindowsFormsHost中调用Windows窗体控制方法

[英]Call windows forms control method inside wpf's WindowsFormsHost

I have created my own WindowsFormsControl. 我已经创建了自己的WindowsFormsControl。 This control has a public method LoadDocument: 此控件具有公共方法LoadDocument:

public partial class SignNowFormsControl : UserControl
{
    public SignNowFormsControl()
    {
        InitializeComponent();
    }

    public void LoadDocument(string PathToDocument)
    {
        Console.WriteLine("Dokument " + PathToDocument + " wird geladen.");
    }
}

Now, I embed this control in wpf's xaml: 现在,我将此控件嵌入到wpf的xaml中:

<WindowsFormsHost x:Name="SignNowFormsHost" Margin="0,0,0,0">
    <signNowFormsControl:SignNowFormsControl x:Name="SignNowFormsControlItem" x:FieldModifier="public" />
</WindowsFormsHost>

In code behind I try now to call the LoadDocument method of the control: 在后面的代码中,我现在尝试调用控件的LoadDocument方法:

public void LoadDocument(string PathToDocument)
{
    this.SignNowFormsControlItem.LoadDocument(PathToDocument);
}

Now, when I build the project I get the following error: 现在,当我构建项目时,出现以下错误:

'SignNowFormsControl.SignNowFormsControl' does not contain a definition for 'LoadDocument' and no extension method 'LoadDocument' accepting a first argument of type 'adeon.SignNowFormsControl.SignNowFormsControl' could be found (are you missing a using directive or an assembly reference?) 'SignNowFormsControl.SignNowFormsControl'不包含'LoadDocument'的定义,也找不到扩展方法'LoadDocument'接受类型为'adeon.SignNowFormsControl.SignNowFormsControl'的第一个参数(您是否缺少using指令或程序集引用?)

Can someone please explain me what is wrong here? 有人可以解释一下这是怎么回事吗? Is it not possible to use methods with parameters here? 这里不能使用带有参数的方法吗? Do I have to write the values to properties instead? 我是否必须将值写入属性?

The code above does actually work. 上面的代码确实有效。 After cleaning and rebuilding the whole solution there was no build error any more. 清洗并重建整个解决方案后,再也没有构建错误。

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

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