Sorry for this basic question
I have a data model :
class data_test
{
public string textdata { get; set; }
public bool booldata { get; set; }
public bool checkdata { get; set; }
public data_opt enumdata { get; set; }
}
Here's Enum :
enum data_opt
{
managed = 1,
unmanaged = 2 ,
mixed = 3
}
Then I create a data model :
var n_Data = new data_test()
{ textdata = "test data",
booldata = false,
checkdata = true ,
enumdata = data_opt.mixed
};
And I create a text box from code behind :
var text_box = new TextBox();
Now I want to bind text_box.Text property to n_Data.textdata from code behind
The same way DataGrid works , two-way connection with real-time update.
I found some pages :
Binding String Property in Code-Behind TextBlock
WPF Data Binding to a string property
Binding string property to object
Unfortunately , none of them worked for me , Here's my code to bind:
Binding binding = new Binding();
binding.Path = new PropertyPath("textdata");
binding.Source = n_Data;
text_box.SetBinding(TextBlock.TextProperty, binding);
Also I tried this :
Binding binding = new Binding();
binding.Path = new PropertyPath("textdata");
binding.Source = n_Data;
BindingOperations.SetBinding(text_box, TextBlock.TextProperty, binding);
Both of them don't work , What am I doing wrong ?