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.