。 The dependency property is the part that WPF personally finds to be wonderful and most distinctive. So I took it out first.
First, to implement the dependency property, you must inherit dependency Object. If you look at WPF's underlying controls that actually indirectly or directly inherit dependency Object, I'll make a regular statement later.
First dependency Object I move the description of the book
Only the thread, the Dispatcher is created on may access the Dispatcherobject directly. To access a dispatcherobject from a thread other than the thread the Dispatcherobject is created on, call Invoke or Begin Invoke on the Dispatcher the dispatcherobject are associated with.
This fits perfectly with the WPF threading model. First do is related to threads, and only the create thread can access do. That's why the threads we create ourselves in WPF want to change UI elements, then we have to Dispatcher.invoke and BeginInvoke.
DP features and knowledge point information is huge. As a study note, I only list the essence of the content.
1 inheritance
This coincides with the visual tree of WPF.
2 Memory Savings
By default, you can significantly save value settings
3 Multi-value storage (priority)
Enum Basevaluesource
{
Unknown = 0,
Default = 1,
inherited = 2,
DefaultStyle = 3,
Defaultstyletrigger = 4,
Style = 5,
Templatetrigger = 6,
Styletrigger = 7,
Implicitstylereference = 8,
Parenttemplate = 9,
Parenttemplatetrigger = 10,
Local = 11,
}
This priority can answer questions that most update values do not work.
5 Propertychangedcallback
Value change callback.
In particular, it is important to note that all DP value assignments will go through the Set property, and if it is a binding or direct xmal assignment via Express, WPF will take a "sneak" shortcut for itself, and almost all new WPF novices will take a good step.
Well, in the end, personally, I think that DO,DP is designed specifically for the UI by WPF. For custom user controls, it is particularly necessary to deepen understanding.
Also, DP and do are narrow strip for the binding, in short, DP is the "left value" of the binding, and DataContext is the "Rvalue " of the binding.
There is no absolute, of course, do can also be used as "right value", but this is a personal preference, I opinion think do as the right value a bit "too heavy". Understanding from the inside helps WPF learn.
Learning materials for do and DP
One-Stop wpf--dependency property (DependencyProperty) One
One-Stop wpf--dependency property (DependencyProperty) Two
WPF Foundation to enterprise Application series 7--deep Anatomy of dependency properties
WPF Basic Learning Note (i) Dependency Object and Dependency property