Data Binding in three modes.
1. Onetime: one-time binding. The source data update target is used when the binding is created. It is applicable to displaying data only without updating data.
2. oneway: one-way binding. It is used to display changed data when the binding is created or when the source data changes.
3. twoway: bidirectional binding. source data and target data can be updated at any time.
The binding syntax can be represented by braces. The following are several examples:
<Textblock text = "{binding age}"/>
Equivalent:
<Textblock text = "{binding Path = age}"/>
Or explicitly write the binding direction:
<Textblock text = "{binding Path = age, mode = oneway}"/>
According to the data binding semantics, the default value is Onewa Y. That is to say, if the background data changes, the control related to the binding relationship established in the foreground should also be updated.
In a small example, the slider value is used to control the width of the rectangle control image.
< Grid X: Name = "Contentpanel" Grid. Row = "1" Margin = "12, 0, 12, 0" >
< Grid. rowdefinitions >
< Rowdefinition Height = "*" />
< Rowdefinition Height = "*" />
< Rowdefinition Height = "*" />
</ Grid. rowdefinitions >
<! -- This is the bound resource, and its value changes will cause the changes in the following rectangle. -->
< Slider Name = "Slider"
Value = "90"
Grid. Row = "0"
Maximum = "180"
Margin = "24" />
< Textblock Name = "Txtblk"
Text =" {Binding elementname = slider, Path = value} "
Grid. Row = "1"
Fontsize = "48"
Horizontalalignment = "Center"
Verticalalignment = "Center" />
< Rectangle Grid. Row = "2"
Width =" {Binding elementname = slider, Path = value} "
Rendertransformorigin = "0.5 0.5"
Fill = "Blue" >
< Rectangle. rendertransform >
< Rotatetransform X: Name = "Rotate"
Angle = "90" />
</ Rectangle. rendertransform >
</ Rectangle >
</ Grid >