1

I've created textboxes to use them in winforms - the textbox is done in wpf and integrated in the form. The problem is when I input some text in it, it doesn't really "read" it. The name of the textbox is elementHost1, and if I go like this:

string input1 = elementHost1.Text;

and I write something in the textbox, it's not shown in the string. Is there something wrong in the WPF code? I checked for something saying "IsReadOnly" but there wasn't anything like that.

H.B.
  • 166,899
  • 29
  • 327
  • 400
Gero Perov
  • 35
  • 1
  • 6
  • Check this answer, note the use of the Text property: http://stackoverflow.com/questions/4024798/trying-to-use-the-c-sharp-spellcheck-class/4026132#4026132 – Hans Passant Mar 10 '12 at 22:09

2 Answers2

2

No, the name of the ElementHost is elementHost1. The text box is hosted inside of that. You'll need to get at the actual object inside the element host in order to get at the text.

To do that, access the .Child property to get at the textbox hosted inside the ElementHost:

var elementHost = this.elementHost1;
var wpfTextBox = (System.Windows.Controls.TextBox)elementHost.Child;
var text = wpfTextBox.Text;
Judah Gabriel Himango
  • 58,906
  • 38
  • 158
  • 212
  • How to do it? MSDN doesn't help a lot. I tried several schemes, most of the time the code didn't compile and once it did but it didn't work again. – Gero Perov Mar 10 '12 at 22:38
0

Have a look at http://msdn.microsoft.com/en-us/library/ms742215.aspx, which describes how to send data back to the WinForms host application.

devdigital
  • 34,151
  • 9
  • 98
  • 120