Silverlight/WP7 multibinding

Source: Internet
Author: User
Tags silverlight

In this article, I will introduce an upgraded version of Silverlight multi-value binding that I wrote last year. The upgraded version includes Silverlight 4, additional attributes, and multi-value binding to an object.

Multi-value binding in WPF allows you to bind multiple data sources to a single attribute. In this case, the binding must be combined with a value converter. However, this feature is not supported in Silverlight. A year ago, I wrote a solution about how to solve multibinding in Silverlight, which was greatly affected. Microsoft's attorney even sent me an email saying that I could use the solution I wrote to the Silverlight Facebook client (what a cool thing ). I'm glad to hear that Stefan Olson has an upgraded version so that it can be used in sl4. This article briefly introduces the new features of these upgrades.

The following figure shows an example of multi-value binding:

In this example, the textbox at the top is bound to the surname and forename attributes of the data object through a converter (the first letter and forename of surname are intercepted ). If you edit forname or surname, the value of textbox at the top will also change accordingly. This technique links three attributes and binds them through different converters.

The following is the XAML code that implements the above functions:

<TextBlock x:Name="Block" Foreground="White" FontSize="13" Margin="5,0,0,0">    <local:BindingUtil.MultiBindings>        <local:MultiBindings>            <local:MultiBinding TargetProperty="Text"  Converter="{StaticResource Title SummaryConverter}">                <local:MultiBinding.Bindings>                    <local:BindingCollection>                        <Binding Path="Surname"/>                                                    <Binding Path="Forename"/>                        </local:BindingCollection>                </local:MultiBinding.Bindings>            </local:MultiBinding>            <local:MultiBinding TargetProperty="ToolTipService.ToolTip"  Converter="{StaticResource TitleConverter}">                <local:MultiBinding.Bindings>                    <local:BindingCollection>                        <Binding Path="Surname"/>                                                    <Binding Path="Forename"/>                        <Binding Path="Age"/>                    </local:BindingCollection>                </local:MultiBinding.Bindings>            </local:MultiBinding>        </local:MultiBindings>    </local:BindingUtil.MultiBindings></TextBlock>

Here we can see that textblock has two multibinding attributes: forename and surnade, and three attributes.

Noto: The second multibinding is bound to tooltipservice, and tooltip is an additional property.

You can download the Silverlight multibinding source code: slmultibindingupdate.zip. Thanks again Stefan Olson for adding this feature to WPF.

If you are interested in the principles of this technology, I recommend you read this article, which describes how to build a virtual branch in the visualization tree to evaluate your bindings code.


I hope this upgraded version will be useful to you. If you have any feedback, please leave a message.

You can download the Silverlight multibinding source code: slmultibindingupdate.zip

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.