You are going to have to use Data Binding here. You should create a public string property in your code behind and bind the Text property of your data template textbox to that property.
<DataTemplate>
<TextBox Text="{Binding Path=Name}"/>
</DataTemplate>
string name;
public string Name
{
get
{
return name;
}
set
{
if (name != value)
{
name = value;
OnPropertyChanged("Name");
}
}
}
void SetTextBoxText(string value)
{
Name = value;
}
You need to ensure that your form implements INotifyPropertyChanged and that the forms datacontext is set to this
this.DataContext = this;
Hope this helps