1. An object class needs to implement the "inotifypropertychanged" interface
Code
Public Class Student: inotifypropertychanged
{
String Name;
Public string name
{< br> Get { return name ;}
set
{< br> name = value;
// here we need to pass "name ", instead of private variable "name"
policypropertychange ( " name " );
}< BR >}
Public IntAge {Get;Set;}
# RegionInotifypropertychanged Member
Public Event Propertychangedeventhandler propertychanged; // Inotifypropertychanged interface delegate
Private Void Notifypropertychange ( String Propertyname)
{
If (Propertychanged ! = Null )
{
// Notification update: all controls bound with propertyname and property update interface values
Propertychanged ( This , New Propertychangedeventargs (propertyname ));
}
}
# Endregion
}
2. in XAML, set the update direction of the control binding: <SDK: Label Height = "28" content = "{binding name, mode = twoway }"
Code
< Grid X: Name = " Layoutroot " >
< Textbox height = " 23 " Horizontalalignment = " Left " Margin = " 250,144, 0, 0 " Name = " Txtname " Verticalalignment = " Top " Width = " 120 " />
< SDK: Label height = " 23 " Content = " Name: " Horizontalalignment = " Left " Margin = " 175,144, 0, 0 " Name = " Label1 " Verticalalignment = " Top " Width = " 69 " />
< Button content = " OK " Height = " 23 " Horizontalalignment = " Left " Margin = " 250,215, 0, 0 " Name = " Btnok " Verticalalignment = " Top " Width = " 75 " Click = " Btnok_click " />
< SDK: Label height = " 28 " Content = " {Binding name, mode = twoway} " Horizontalalignment = " Left " Margin = " 175,103, 0, 0 " Name = " Labmessage " Verticalalignment = " Top " Width = " 120 " />
< Textbox height = " 23 " Horizontalalignment = " Left " Margin = " 250,173, 0, 0 " Name = " Txtage " Verticalalignment = " Top " Width = " 120 " />
< SDK: label content = " Age: " Height = " 23 " Horizontalalignment = " Left " Margin = " 175,173, 0, 0 " Name = " Label3 " Verticalalignment = " Top " Width = " 69 " />
</ Grid >
3. In CSCodeUpdate object class dependency attributes
Code
Public Partial Class Page1: Page
{
Student mystudent = New Student ();
PublicPage1 ()
{
Initializecomponent ();
Mystudent. Name= "Zhang San";
Mystudent. Age= 20;
This . datacontext = mystudent;
}
Private VoidBtnok_click (ObjectSender, routedeventargs E)
{
//When mystudent. Name is updated, the value of labmessage. Content is automatically updated.
Mystudent. Name=Txtname. text;
}
}