共用方式為


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 [bindingPropertyName=value][, bindingPropertyName=value]*}" .../>

XAML Object Element Usage

<object>
  <object.property>
    <Binding[ bindingPropertyName="value"]*.../>
  </object.property>
</object>

Any of the properties listed above, 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

NoteNote:

The [] brackets in the syntax above are not literals, they are optional indicators, to connote that a binding may have zero or more bindingPropertyName=value pairs specified in the Binding markup extension syntax. The * shown is also not syntactical, and is again an indicator that multiple bindingPropertyName=value pairs beyond the first one can be added, with each pair separated by a comma in the attribute syntax, or by spaces in the object element syntax. The object element syntax is really the same object element syntax as is shown on the Binding class page, but the one in this topic provides guidance about which properties of Binding are settable as attributes on a Binding object element.

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 to the property. 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=values 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 Syntax section in the reference for each property listed below, to determine the proper syntax for setting its value as an attribute in XAML; attribute syntax for any given property is the same form as the value form that must be given for the Binding markup extension property=value pairs.

The following are properties of Binding that cannot be set through XAML syntax and 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.

NoteImportant:

In terms of dependency property prededence, 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.

NoteNote:

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 reader 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.

See Also

Reference

Binding

Concepts

Data Binding Overview
Binding Declarations Overview
XAML Overview
Markup Extensions and XAML