How do I get the text out of a System.Windows.Controls.TextBox in a Windows Application Form?

I need to have spellcheck available for users in my windows application.  I inserted a WPF Interoperability ElementHost onto my form and used this code to set it up.  It works great.

using System.Windows;
using System.Windows.Controls;


Code to get it working:
 var memoBox = new System.Windows.Controls.TextBox();
memoBox.SpellCheck.IsEnabled = true;
 txtMemoField.Child = memoBox;

Now I need to save what is typed in the elementhost.  Here is my code:
tblS.MemoField = Convert.ToString(this.txtMemoField.Child);

This retrieves:  "System.Windows.Controls.TextBox:  what's been typed"

I just want "what's been typed."   How do I do code for this because I can see it in there (all by itself) when I debug, I just can't get it.

Many thanks!
Karen WilsonAsked:
Who is Participating?
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
*I don't work in WPF...sorry.

You may need to CAST the child to its proper type before you can see the .Text() property.  

tblS.MemoField = ((System.Windows.Controls.TextBox)this.txtMemoField.Child).Text.ToString();

Open in new window

Peter HutchisonSenior Network Systems SpecialistCommented:
You need to use the .Text property of the textbox to get the text out of it.
Karen WilsonAuthor Commented:
That does not work.  Tried it...  If I use this.txtMemoField.Text I get "".  I use child, at least I get something.  Now I need to drill down in child to get just the text.
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Mike TomlinsonMiddle School Assistant TeacherCommented:
Try using .Text() against the CHILD?

    tblS.MemoField = Convert.ToString(this.txtMemoField.Child.Text);
Karen WilsonAuthor Commented:
I just get TextInput as a choice.  I typed it in as well to see what happened and it didn't like it.  When I drill down, I open the System. Windows.Controls.TextBox, I can see it all by itself under Text.
Karen WilsonAuthor Commented:
And there it is!!  THANKS!!!!!!!!!!!!!!!!  I knew I'd get the answer from you!!  

Have a great day....
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.