6 of the WPF Learning Series (element binding)

Source: Internet
Author: User

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)

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.