Printer Friendly Version      Send     
Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Silverlight
 Binding Markup Extension
Silverlight 2
Binding Markup Extension (Silverlight 2)
[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

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.

<object property="{Binding}" .../>

-or-

<object property="{Binding propertyPath}" .../>

-or-

<object property="{Binding oneOrMoreBindingProperties}" .../>

-or-

<object property="{Binding propertyPath, oneOrMoreBindingProperties}" .../>

propertyPath

A string that specifies the property path for the binding. See "Property Paths" section.

oneOrMoreBindingProperties

bindingPropertyName=value[bindingPropertyName=value]*

The []* in the syntax are not literals. They are indicators that more than one name/value pair is possible.

Each name/value pair should be separated from other name/value pairs. The separator can be either a comma or a space.

bindingPropertyName

The string name of the Binding property to set. 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.

Property Paths

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 "dot down" into the object model of a CLR object 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.Name. 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.

For further details on 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 support s property path techniques for retrieving indexed items in a collection and for retrieving attached property values. Silverlight 2 Beta 2 currently does not provide this support. A Silverlight 2 Beta 2 property path is a series of steps into an object model and only supports the "dotted" syntax.

Binding Properties That Can Be Set with the Binding Extension

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), can use built-in parsing behavior and simply pass the value.

  • 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).

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.

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.

© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker