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}" .../> <someFrameworkElementproperty="{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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access