I am using a WPF textbox inside an element host in a Winforms project.
I would like to databind this textbox to a bindingsource as I do with the standard winforms textbox like so:
Me.tbxCorrectiveAction.DataBindings.Add("Text", bgsTasks, "CorrectiveAction", False)
This is what I have tried:
Dim host As New System.Windows.Forms.Integration.ElementHost()
Dim wpfTextBox As New System.Windows.Controls.TextBox()
wpfTextBox.SpellCheck.IsEnabled = True
host.Dock = DockStyle.Fill
host.Child = wpfTextBox
Me.Panel8.Controls.Add(host)
Dim binCorrectiveAction As New System.Windows.Data.Binding("CorrectiveAction")
binCorrectiveAction.Source = bgsTasks
wpfTextBox.SetBinding(System.Windows.Controls.TextBlock.TextProperty, binCorrectiveAction)
Solutions in either VB or C# are fine.
Try this:UPDATE.
There’s an error in your code (or just a typo, which causes a logical error).
You’re trying to bind TextBlock.TextProperty on a TextBox control.
There should be
TextBox.TextProperty:The reason is that these dependency properties (and controls) are differ, in spite of they have similar names.
If it isn’t a typo, then I recommend you to read about WPF dependency properties mechanism here.