-1

Basically I have a WPF elementHost contained in my C# Windows Form. The element host needs to retrieve a variable from the Windows form, but I have found no simple way to communicate between the two of them. Is there any method in particular I should be looking out for?

I've tried the standard

Textbox.Text = form2.Variable;

But this doesn't seem to work within the WPF elementhost.

Sorry for the vagueness! I just don't know where to start!

David
  • 9
  • 2
  • 1
    Welcome to Stackoverflow! What have you tried so far? please provide some code, approaches or where you failed otherwise we wont be able to help you – colosso Jan 24 '18 at 09:24
  • I've tried something along the lines of ---- Box.Text = form2.Variable; --- But this doesn't seem to work with the WPF elementHost – David Jan 24 '18 at 09:26
  • 1
    You will need to put your code in the question and explain more about what you are trying to do. Your question is too vague to offer much help. – Rob Anthony Jan 24 '18 at 09:31

1 Answers1

0

Basicly, In your wpf class declare a public method which returns a value

 //in your wpf class (class of your screen)
    public string GetTextBoxText()
    {
        return myTextBox.Text;
    }

In your winforms, in your winforms you can access to this method as :

  MyWpfApp myApp = new MyWpfApp();
  var text = myApp.SetTextBoxText();

Or you can declare a public property in your wpf class to get or set the textbox value.

    public string MyValue
    {
        get
        {
            return myTextBox.Text;
        }
        set
        {
            myTextBox.Text = value;
        }
    }


    MyWpfApp myApp = new MyWpfApp();
    var text = myApp.MyValue;
Coskun Ozogul
  • 2,389
  • 1
  • 20
  • 32