Data Binding Basics
Slider: Progress bar
<slider Name = "Slider1" ...></slider>
<textbox Text = "{Binding Value, elementname = slider1}" ></TextBox>
Write a data-bound class:
Class Person
{
}
Background:
person P1 = new person ();
Txtname.datacontext = p1;
Txtage.datacontext = p1;
Front:
<textbox Text = "{Binding Name}"
<textbox Text = "{Binding Age}"
Try not to manipulate the control directly, but create a new class , new instance, to set the control to bind DataContext
Txtname.datacontext = p1;
<textbox Text = "{Binding Name}"
INotifyPropertyChanged
<textbox TextChange
. NET built-in interfaces
Data binding detects if the DataContext implements INotifyPropertyChanged
If implemented, it will listen to propertychanged to learn about the property changes.
Class person:inotifypropertychanged
{
private int age;
public int Age
{
Get
{
return age;
}
Set
{
This.age = value;
if (propertychanged! = null)
{
PropertyChanged (This, new PropertyChangedEventArgs ("Age"));
}
}
}
Intelligence Podcast--Data binding basics