WPF attached properties

Source: Internet
Author: User

An attached property is also a dependency property, which means that a property is not part of an object, but because a requirement is later appended, that is, the attribute is placed after the object is in a specific environment

Example: People in school have age and class two attributes, people put in school will get grade and class two attribute description grade and class two attributes are attached to the school. So the real owner of these two properties should be the school

1.1. Customizing additional properties

 Public classSchool { Public Static intgetgrade (DependencyObject obj) {return(int) obj.        GetValue (Gradeproperty); }         Public Static voidSetgrade (DependencyObject obj,intvalue) {obj.        SetValue (gradeproperty, value); }        //Using a DependencyProperty as the backing store for Grade. This enables animation, styling, binding, etc ...         Public Static ReadOnlyDependencyProperty Gradeproperty =dependencyproperty.registerattached ("Grade",typeof(int),typeof(School),NewPropertyMetadata (0)); }
// Customizing the Use  of attached properties New Human ();   6 );   int grade = School.getgrade (human);  MessageBox.Show (grade. ToString ());

WPF attached properties

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.