Binding Markup Extension
Defers a property value to be a data-bound value, creating an intermediate expression object and interpreting the data context that applies to the element at run time.
XAML Attribute Usage
<object property="{Binding}" .../>
-or-
<object property="{Binding
bindingPropertyName1=value,
bindingPropertyName2=value,
bindingPropertyNameN=value}" ...
/>
XAML Object Element Usage
<object>
<object.property>
<Binding/>
</object.property>
</object>
-or-
<object>
<object.property>
<Binding
bindingPropertyName1="value"
bindingPropertyName2="value"
bindingPropertyNameN="value"
/>
</object.property>
</object>
Any of the properties listed below, which would be set as a property=value pair in the example attribute syntax, can instead be set as attributes of the Binding element as defined in object element syntax.
XAML Values
bindingPropertyName# |
The Name of the Binding property to set. Not all Binding properties can be set with the Binding extension, and some properties are settable only by using further nested markup extensions. See "Binding Properties That Can Be Set with the Binding Extension" section. |
value |
The value to set the property to. The handling of the attribute value is ultimately specific to the type and logic of the bindingPropertyName being set. |
Binding Properties That Can Be Set with the Binding Extension
The syntax shown in this topic uses the generic bindingPropertyName=value approximation, because there are many read/write properties of BindingBase or Binding that can be set through the Binding markup extension syntax. They can be set in any order. Basically, you can set zero or more of the properties in the list below, using property=value pairs separated by commas.
Several of these property values require object types that do not support a native type conversion, and thus require further markup extension usages to be set in XAML as an attribute value. Check the XAML Attribute Usage section in the reference for each property to determine the proper attribute syntax.
BindsDirectlyToSource: bool type, can be either true or false.
Converter: can be set in XAML, but to do so requires an object reference such as a StaticResource Markup Extension.
ConverterCulture: settable as a standards-based identifier; see the reference for ConverterCulture.
ConverterParameter: if passing a by-reference type, requires an object reference such as a StaticResource Markup Extension.
ElementName: mutually exclusive vs. RelativeSource, Source; each of these properties represents a particular binding methodology. See Data Binding Overview.
FallbackValue: if passing a by-reference type, requires an object reference such as a StaticResource Markup Extension.
Path: see PropertyPath XAML Syntax.
RelativeSource: mutually exclusive vs. ElementName, Source; each of these properties represents a particular binding methodology. See Data Binding Overview. Requires RelativeSource MarkupExtension usage.
Source: mutually exclusive vs. RelativeSource, ElementName; each of these properties represents a particular binding methodology. See Data Binding Overview. Requires an object reference such as a StaticResource Markup Extension.
The following are properties of Binding that cannot be set using the Binding markup extension.
Remarks
The bindingPropertyName placeholders given here correspond to the names of some of the declared settable properties of the Binding class, and the value strings are equivalent to how those property values would be set as a XAML attribute within a Binding declared as a XAML element.
Describing data binding as a concept is not covered here; see Data Binding Overview for concepts and Binding Declarations Overview for more details on alternate syntax. Alternate syntax discussion includes how to create equivalent bindings by a number of possible syntaxes, such as attribute properties of a Binding object element in XAML, property element syntax of a Binding, or procedural creation of a binding using SetBinding or the Binding constructor.
Important Note: |
---|
In terms of dependency property precedence, a Binding expression is equivalent to a locally set value. If you set a local value for a property that previously had a Binding expression, the Binding is completely removed. For details, see Dependency Property Value Precedence. |
Note
MultiBinding and PriorityBinding do not support a XAML extension syntax (despite sharing the same BindingBase class, which actually implements the XAML behavior for Binding).
Binding is a markup extension. Markup extensions are typically implemented when there is a requirement to escape attribute values to be other than literal values or handler names, and the requirement is more global than just putting type converters on certain types or properties. All markup extensions in XAML use the { and } characters in their attribute syntax, which is the convention by which a XAML processor recognizes that a markup extension must process the attribute. For more information, see Markup Extensions and XAML. Binding is an unusual markup extension in that the Binding class that implements the extension functionality also implements several other methods and properties. These other members are not directly a requirement for markup extension functionality. The members are intended to make Binding a more versatile and self-contained class that can address many data binding scenarios in addition to functioning as a XAML markup extension.