c # UWP controls Button (III)

( Back to Contents )

 

Summary of Properties

 

 
dependency property (DependencyProperty)
Dependent attribute is a specific type of attribute. Special about this property is that property values ​​be tracked and its impact in the private property system Windows is running.

Dependent attribute value is not stored as a field in the class, they are stored by the XAML frame and referenced using the key, the key will be used by the calling method DependencyProperty.Register retrieve a Windows system run-time attributes of the attribute register.

Dependency property only be used by the type derived from DependencyObject. DependencyObject class hierarchy is located in a very high level, so most of the class and demonstrate support for UI can support dependency property.
 
Convention as follows: Each attribute dependency disclosed a class has a corresponding public static readonly DependencyProperty type attribute, the attribute-dependent properties and provide a disclosure on the same class identifier. Name Identifier of the following convention: dependency property + "Property". For example, Control.Background DependencyProperty identifier corresponding to the attribute is Control.BackgroundProperty.
 
Dependency property priority list:
   1, the value of the animation
   2, local value
   3, the template attribute
   4, type repository.
   5, the default value
 
Its dependent attribute value can be set by the application data binding. Binding data used in XAML markup extension syntax {Binding}, {x: Bind} markup extension or the Binding class code. For data binding properties, and ultimately determine property values ​​to be delayed until run-time.
 
{Binding} to be used as targets or markers extended Binding of the attribute must be a dependency property. {X: Bind} no such requirement, since it uses to generate application code that bind value.

If you create a binding code, please note SetBinding API only FrameworkElement definition.
 
For code or XAML, remember that DataContext is a FrameworkElement property.
 
 
additional properties
XAML attached property is a concept.
 
 Using additional attributes, other attributes may be provided on the object / value pairs, but these properties are not part of the original object definition. Additional property generally defined as a specialized form of dependency property, no traditional packaging property owner in the object model type.
 
In XAML syntax may be used provided AttachedPropertyProvider.PropertyName additional properties. For example: Canvas.Left.
 
Use additional properties, it may be avoided to prevent the transmission of information coding convention a mutual relationship between different objects at run time.
 
Two settings additional properties in the code mode: API using the property system or XAML mode access device.
 
 
 
⚫ additional property attributes dependent differences

A method RegisterAttached additional property used, and dependency properties using methods Register

2. Additional methods for packaging two properties, properties dependent on the use of two methods GetValue CLR property Set Value and packaging.

3. Additional attributes are applied to the class that is not defined in the attached property class dependent attributes are applied to that defined in the attached property class.
 
(Quoted from: rope life so well I guess)

Guess you like

Origin www.cnblogs.com/flyarrow/p/11875381.html
UWP