C#将数据发送到elementHost

时间:2018-01-24 09:20:40

标签: c# wpf elementhost

基本上我的C #Windows窗体中包含一个WPF elementHost。元素主机需要从Windows窗体中检索变量,但我发现没有简单的方法在它们之间进行通信。是否有任何方法特别值得我注意?

我已尝试过标准

Textbox.Text = form2.Variable;

但这似乎不适用于WPF elementhost。

抱歉模糊不清!我只是不知道从哪里开始!

1 个答案:

答案 0 :(得分:0)

基本上,在你的wpf类中声明一个返回值

的公共方法
 //in your wpf class (class of your screen)
    public string GetTextBoxText()
    {
        return myTextBox.Text;
    }

在winforms中,您可以在winforms中访问此方法:

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

或者您可以在wpf类中声明一个公共属性来获取或设置文本框值。

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


    MyWpfApp myApp = new MyWpfApp();
    var text = myApp.MyValue;
相关问题