Silverlight dependency attributes

Source: Internet
Author: User

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;
}
}

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.