The Path of a binding is conceptually similar to its "default property" in the Binding markup extension usage. You can establish the Path either through the string immediately after the {Binding initial part of the Binding markup extension, or through the Binding constructor in code. Optionally, you can also specify Path= explicitly as a named argument in the Binding markup extension usage.
The Path for a binding is a property path. A property path is a string that is evaluated as instructions to search an object for a property of that name and return the value. The property path can be used to traverse into the object model of a CLR object or DependencyObject in cases where the value of the initially named property is an object, and the value you want is from a subproperty of that object.
The delimiter between steps in a property path is a dot (.). You can include multiple delimiters to reference successive subproperties until the desired property value is reached.
For example, you might bind to a business object that represents an employee. If you wanted to bind UI to the string for the employee's first name, your data binding path might be Employee.FirstName. Or, if you were binding an items control to a collection property that lists the employee's dependents, your data binding path might be Employee.Dependents, and a data template applied to the items control would take care of displaying individual properties of the Dependents items.
If the data source is a collection, then the property path specifies properties to be found on a collection item object.
When using ElementName binding to an existing DependencyObject, you can use attached properties as part of the property path. To disambiguate attached property usages so that the intermediate dot in the attached property name is not considered a step into a path, put parentheses around the owner-qualified attached property name; for example, (Validation.Errors).
For more information about the string syntax for a property path, as well as parallel usages for property paths in animation feature areas and for constructing a PropertyPath object, see Property Path Syntax.
Note: |
|---|
If you are familiar with WPF data binding, you know that WPF supports property path techniques for retrieving indexed items in a collection and for retrieving attached property values. Silverlight 3 supports these techniques, but with limitations. See Property Path Syntax. |
The syntax shown in this topic uses the grammar bindingPropertyName=value because there are multiple read/write properties of 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 named in the following list, in any order, using bindingPropertyName=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, nested within the Binding markup extension:
Path. As noted in the preceding "Property Paths" section, you can establish the Path through the string immediately after the {Binding initial part of the Binding markup extension, or you can also specify Path= explicitly in the usage just like the other named Binding properties.
Converter. Can be set in XAML, but only if you are referring to a converter that is defined in such a way that it can be instantiated and placed in a ResourceDictionary in XAML. The XAML reference then requires a StaticResource reference to that object in the resource dictionary.
ConverterCulture. Settable as a standards-based identifier; see the reference for ConverterCulture.
ConverterParameter. If passing a reference type, can be set in XAML, but only if you are referring to an object value that is defined in such a way that it can be instantiated and placed in a ResourceDictionary in XAML. The XAML reference then requires a StaticResource reference to that object in the resource dictionary. If passing a primitive (such as a string or integer), you can use built-in parsing behavior and simply pass the value. But for nonprimitives, the TypeConverter pathway for obtaining an object from a string is not available because there is no way to identify which object you want to convert to based on the Object type of ConverterParameter.
Mode. Specifies the binding mode, as one of the following strings: OneTime, OneWay, TwoWay.
Source. Specifies the object data source. For usage within the Binding markup extension, requires an object reference such as a StaticResource reference. If this is left unspecified, the acting data context specifies the source.
NotifyOnValidationError. Enables a validation/notification mode on the binding. Can be true or false (default is false).
ValidatesOnExceptions. Enables a validation/notification mode on the binding. Can be true or false (default is false).
ElementName. Specifies a data source by referencing another element that has a Name property or x:Name Attribute (the ElementName usage specifies that name). The element must exist in the same XAML namescope.
RelativeSource. Specifies a data source by describing the position of the binding source relative to the position of the binding target. This is expressed in terms of the run-time object graph, and can be Self or TemplatedParent. Whether set in attribute form or as a binding property in the expression, setting RelativeSource in XAML requires using the RelativeSource Markup Extension.
UpdateSourceTrigger. Determines the timing of binding source updates, as one of the following strings: Default, Explicit. The default if unspecified is the Default update mode.