Call windows forms control method inside wpf's WindowsFormsHost

975 views Asked by At

I have created my own WindowsFormsControl. This control has a public method 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:

<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:

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?)

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?

1

There are 1 answers

0
marco birchler On

The code above does actually work. After cleaning and rebuilding the whole solution there was no build error any more.