You need to set a name for the text field so that you can refer to it in the code. Then you just have to assign the object to the DataContext property. You can create data binding tactically:
Binding binding = new Binding(); binding.ElementName = "listBox1"; binding.Path = new PropertyPath("SelectedItem"); binding.Mode = BindingMode.OneWay; txtMyTextBox.SetBinding(TextBox.TextProperty, binding);
source share