A few days ago I was exploring the possibilities of WPF zažal coded. within a few days I started to use DataBindings. Nowhere on the Web site did not find any simple example of the use to upload DataBindings Object invoked from Codebehind.
Here is a simple example .. First you need to design the form.
Insert two TextBox elements. Two Lebel and one button.
The result will look like the picture ..
then switches to the CS code file and create the following class bData
public class bData
{
Public bData (string val1, string val2)
{
this.val1 = val1;
this.val2 = val2;
}
public string val1 {get, set;}
public string val2 {get, set;}
}
Class bData can take only two string values [ val1 and val 2]
Our task will be after you press button Load Values, to display data in textbox using DataBinding.
So switch to the XAML editor and modify the textbox text value
For the first texbox
Text = "{Binding Path = val1}"
to the second
Text = "{Binding Path = val2}"
hereby will get a object from the recorded value is displayed as text in val1 and val2 in texbox1 and textbox2
still need a code to the button. Then create method Click and write this line
this.DataContext bData = new ("test"; "test2");
This line load bData to current datacontext. When object is loaded. Textboxs take value by definiting of databining and show the values.
That's all. I hope that helps to understand simpliest usage of databinindg in WPF.
Happy coding :-\