XAML overview-property and event binding

Source: Internet
Author: User

XAML specifies a language feature that allows you to specify certain attributes or events on any element without worrying about whether these attributes or events exist in the member table of the corresponding element. If an attribute is specified, it is called property binding. If an event is specified, it is called event binding. In terms of concept, attribute binding and event binding can be used as the set element or global member of the class without concern about the inheritance relationship of their class.

Generally, attribute binding in XAML uses the attribute syntax. In this syntax, the ownertype. propertyname format is used to bind attributes. On the surface, this format is similar to the property element syntax, but the owenertype specified here is different from the type of the element currently set to bind the property object. The ownertype type provides the accesser methods required by the XAML accesser, which facilitates obtaining or setting the value of the binding attribute. The most common usage of attribute binding is that a child element reports its property value to its parent element.

The following example demonstrates the BIND property dockpanel. Dock. The dockpanel class defines the accessors for dockpanel. Dock, so it has the binding attribute. The dockpanel class also contains the logic to iterate its own sub-elements and check the set value of each of its elements if dockpanel. when the set value of the dock is found, this value will be used for positioning the child element.

<Dockpanel>
<Button dockpanel. Dock = "Left" width = "100" Height = "20"> I am on the left </button>
<Button dockpanel. Dock = "right" width = "100" Height = "20"> I am on the right </button>
</Dockpanel>

Event binding is similar to ownertype. the attribute syntax format of eventname. Similar to non-event binding, the attribute value of an event bound in XAML specifies the name of the processing method to be called when an event on this element is processed.
Related Article

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.