XAML’s Binding Markup Extensions

One of the main pieces of functionality that dependency properties offer is their ability to be data-bound. In XAML, the data binding works through a specific markup extension syntax. Alternatively, you can establish the binding through .NET code. Both ways are effective and will be demonstrated in this chapter.

A set of XAML attributes exists to support the data-binding features. The following pseudocode examples represent basic usage of these extensions:

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

<someFrameworkElement property="{Binding pathvalue}" .../>

<someFrameworkElement property="{Binding Path=pathvalue}" .../>

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

<someFrameworkElement property
    ="{Binding pathvalue, oneOrMoreBindingProperties}" .../>

In the preceding code, the element must be a FrameworkElement (thus, the name someFrameworkElement). You would replace property with the name of the property that will be the target of the binding. For example, the element might be a TextBox and the property might be Text. To bind the value of the property to a source, you can use the binding markup extensions.

The Binding attribute indicates that the value for the dependency property will come from a data-binding operation. The binding gets its source from the DataContext for the element. If the element does not have a DataContext, the XAML hierarchy is examined to see whether any parent XAML container element has a ...

Get Data-Driven Services with Silverlight 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.