Silverlight Data Binding onetime, oneway, twoway

Source: Internet
Author: User

onetime: one-time binding. when data is bound to the control, the binding ends.
oneway: Changing the data source will affect the control bound to the data source.
twoway: changing the data source affects the control bound to the data source, and changes in the data in the control also affect the data source
1. Onetime
Foreground:

<TextboxText="{Binding name, mode = onetime}"Height= "23"Horizontalalignment= "Left"Margin= "114,92, 0, 0"Name= "Textbox1"Verticalalignment= "TOP"Width= "120" />

Background:

 Public  Class  Person {  String  Name;  Public   String  Name {  Get { Return  Name ;}  Set {Name = Value ;}} person P = New  Person ();  Public Mainpage () {initializecomponent (); p. Name = "  Qiao Feng  "  ; Textbox1.datacontext = P ;} 

Ii. oneway
Front-end:

 <  Textbox  Text  ="  {Binding name, mode = oneway}  "  Height  = "23"  Horizontalalignment = "Left"  Margin  = "114,92, 0, 0"  Name  = "Textbox1"  Verticalalignment  = "TOP"  Width  = "120"   />  <  Button  Content  = "Oneway"  Height  = "23" Horizontalalignment  = "Left"  Margin  = "159,182"  Name  = "Button1"  Verticalalignment  = "TOP"  Width  = "75"  Click  = "Button#click"   /> 

Background:

 Public   Class Person: inotifypropertychanged//  To bind ONEWAY and twoway, You need to implement an interface.  {  String  Name;  Public   String  Name {  Get { Return  Name ;}  Set  {Name = Value; policychange ( "  Name  "  );}}  # Region Inotifypropertychanged Member Public   Event  Propertychangedeventhandler propertychanged;  Private   Void Notifychange ( String  Propertyname ){  If (Propertychanged! =Null  ) {Propertychanged (  This , New  Propertychangedeventargs (propertyname ));}}  # Endregion  } Person P = New  Person ();  Public  Mainpage () {initializecomponent (); p. Name = "  Qiao Feng "  ; Textbox1.datacontext = P ;}  Private   Void Button#click ( Object  Sender, routedeventargs e) {P. Name = "  Duan Yu  "  ;} 

When you click the oneway button, changes in the data source will affect the controls bound to the data source.

Iii. twoway
Front-end:

 <  Textbox Text  ="  {Binding name, mode = oneway}  "  Height  = "23"  Horizontalalignment  = "Left"  Margin  = "114,92, 0, 0"  Name  = "Textbox1"  Verticalalignment  = "TOP"  Width  = "120"  />          <  Textbox  Text  ="  {Binding name, mode = twoway}  "  Height  = "23"  Horizontalalignment  = "Left"  Margin  = "114,144"  Name  = "Textbox2"  Verticalalignment = "TOP"  Width  = "120"   /> 

Background:

 Public   Class Person: inotifypropertychanged //  To bind ONEWAY and twoway, You need to implement an interface.  {  String  Name;  Public   String  Name {  Get { Return  Name ;}  Set  {Name = Value; policychange (  "  Name  "  );}}  # Region Inotifypropertychanged Member Public   Event  Propertychangedeventhandler propertychanged; Private   Void Notifychange ( String  Propertyname ){  If (Propertychanged! = Null  ) {Propertychanged (  This , New  Propertychangedeventargs (propertyname ));}}  # Endregion  } Person P =New  Person ();  Public  Mainpage () {initializecomponent (); p. Name = "  Qiao Feng  "  ; Textbox1.datacontext = P; textbox2.datacontext = P ;} 

Bind textbox1 and textbox2 to the same data source. The former is bound in oneway mode, and the latter is bound in twoway mode. When the content in the textbox2 text box is modified and the text box loses focus, the data source value also changes, so that textbox1 and textbox2 both display new values.

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.