MSDN中介绍得比较全面,这里只简单提一下。
MSDN:http://msdn2.microsoft.com/en-us/library/ms752347.aspx
WPF中有个重要的概念Dependency properties:
- They can determine their value by retrieving it from a
Binding
object (i.e. they can be bound). - They can participate in property value inheritance, meaning that if a dependency property on an element does not have a value it will use the value of that property on an ancestor element (in the logical tree). This is somewhat analogous to ambient properties in the Windows Forms world.
- They can be set in XAML, just like a normal property.
DataContext 就是一个Dependency properties:
Binding members :
- Source - references a
Binding
's data source. By default this object references the element'sDataContext
value, which might be inherited from an ancestor element'sDataContext
, as discussed in the previous section. If you set this property to a non-null value, then the data binding operation will treat that value as the place where data is pushed to and pulled from. - Path - is used to indicate from which property on the source object to get and set the bound data value. It is a property of type
PropertyPath
, which allows it to support a complex range of path expressions. - ElementName - can be used as an alternative to the
Source
property described earlier. It allows you to specify the name of an element to use as a data source. This can be useful when binding a property on one element to a property on another element, particularly when the binding is declared in XAML. - Converter - of type
IValueConverter
. You can set this property to an instance of a class which implements that interface to intercept any movement of data from the binding source to the binding target, or vice versa. Value converters are very convenient and are used quite often.