Gero Perov
Gero Perov

Reputation: 35

Getting TextBox data from a control hosted in Winforms

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.

Upvotes: 1

Views: 1934

Answers (2)

Judah Gabriel Himango
Judah Gabriel Himango

Reputation: 60001

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;

Upvotes: 2

devdigital
devdigital

Reputation: 34349

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.

Upvotes: 0

Related Questions