This is a mirror of official site: http://jasper-net.blogspot.com/

MultiBinding in Silverlight 5

| Sunday, November 20, 2011
Introduction

This article presents a MultiBinding implementation for Silverlight 5, enabling aggregating values from several sources to one target dependency property. In contrast to WPF, Silverlight only supports single-value Binding out-of-the-box, but thanks to the support for custom markup extensions introduced in Silverlight 5, it was possible to write a MultiBinding implementation with similar syntax and functionality as the WPF version of MultiBinding.

This markup extension MultiBinding supports all types of source bindings including data context sensitive ones and bindings with named elements and RelativeSource. It also supports two-way binding, i.e., converting back from a single target value to multiple source values. It can also be applied to several elements using styling. In some aspects, this Silverlight version extends the WPF MultiBinding:

    Source bindings can be declared using XAML markup attribute-syntax ({z:MultiBinding}) as a complement to specifying the source bindings in a collection using the element syntax (<z:MultiBinding>).
    The MultiBinding properties Converter, ConverterParameter and StringFormat can be bound dynamically to arbitrary sources using Bindings.
    Sources are not restricted to Bindings. String constants, XAML objects, StaticResource and other markup extensions can be used as individual sources.
    In two-way binding, the normal Silverlight validation mechanism can be used when exceptions are thrown from the user-provided IMultiValueConverter.ConvertBack implementation.
    Converters implementing the single-value IValueConverter can also be used with this MultiBinding, making it useful for single source bindings with Converter, ConverterParameter or StringFormat changing during run-time.

Background

Unlike an ordinary Binding, MultiBinding allows bindings of more than one source to a single dependency property. One common usage is to present a customized text that includes values from several sources. For such scenarios, MultiBinding offers a StringFormat property to define the format with placeholders for the source values to be inserted. But the usage is not restricted to text. A custom IMultiValueConverter can be used to specify how the source values are to be combined.


Read more: Codeproject
QR: SilverlightMultiBinding.aspx

Posted via email from Jasper-net

0 comments: