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