Element Binding
In short, data binding is a relationship that tells WPF to extract some information from a source object and use this information to set the attributes of the target object. The target property always depends on the property and is usually located in the WPF element.
I. Bind elements together
<Window X: class = "studywpf. Element Binding"
Xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml"
Title = "element binding" Height = "300" width = "300">
<Grid>
<Slider name = "sliderfontsize" margin = "3" minimum = "1" Maximum = "40" value = "10" tickplacement = "topleft"> </slider>
<Textblock margin = "10" text = "simple text" name = "lblsampletext" fontsize = "{binding elementname = sliderfontsize, Path = value}"> </textblock>
</GRID>
</WINDOW>
In this way, the font size is bound to the content of the slider value.
2. Binding Error
WPF does not cause exceptions to notify users of issues related to data binding. If the specified element or attribute does not exist, no instructions are received. Instead, data is not displayed in the target attribute.
However, you can see the prompt information in the output window of.
3. binding mode
One feature of data binding is that the target will be automatically updated, no matter how the source is modified, in this example, the source can only be modified in one way, however, after a button is used to change the label font size and then the slider is dragged, the label font size does not change.
6 of the WPF Learning Series (element binding)