Updates to Silverlight Multi-binding support

by StefanOlson 28. April 2010 10:36

Update 29/June/2010: Colin Eberhardt who originally developed this technique has posted an update, including these changes: http://www.scottlogic.co.uk/blog/colin/2010/05/silverlight-multibinding-solution-for-silverlight-4/

The Silverlight multi-binding functionality that I have described previously (see here) doesn't work in Silverlight 4, due to the changes in the xaml parser. This code:

<local:MultiBinding TargetProperty="Text" Converter="{StaticResource TitleConverter}">
    <Binding Path="Surname"/>                            
    <Binding Path="Forename"/>
</local:MultiBinding>

Gives this exception:

System.Windows.Markup.XamlParseException: Set property 'SLMultiBinding.MultiBinding.Bindings' threw an exception

the solution is to wrap the bindings in a binding collection, e.g:

<local:MultiBinding TargetProperty="Text" Converter="{StaticResource TitleConverter}">
    <local:BindingCollection>
        <Binding Path="Surname"/>                            
        <Binding Path="Forename"/>
    </local:BindingCollection>
</local:MultiBinding>

 

You also need to download the latest version of the MultiBinding.cs file, from here

Tags:

Silverlight

Comments

4/28/2010 10:43:52 AM #

Improvements to Silverlight Multi-binding support

Improvements to Silverlight Multi-binding support

Stefan Olson's Blog

4/29/2010 8:05:08 AM #

Pingback from topsy.com

Twitter Trackbacks for
        
        Stefan Olson's Blog | Updates to Silverlight Multi-binding support
        [olsonsoft.com]
        on Topsy.com

topsy.com

5/2/2010 5:40:34 AM #

Thanks for sharing your work.

Currently, the problem is that the converter is called for each parameter int the multibinding.
If you have 3 bindings, the converter is first called with (par1, null, null), after this it is called with (par1, par2, null), and after it is called with all the parameters.

That forces to manage the null values in the converter.  May be you find a way to call the converter only after all parameters are loaded.

Marcos

Marcos Tabaj

5/2/2010 11:12:29 AM #

Pingback from stevepietrek.com

Links (5/2/2010) « Steve Pietrek-Everything SharePoint/Silverlight

stevepietrek.com

5/14/2010 2:47:22 AM #

@Marcos
I wrote about this same problem in a reply to Stefan's previous blog post about this topic. You can see how I solved this problem here:
www.olsonsoft.com/.../...ulti-binding-support.aspx

Please note, however, that I only tested it in my specific case (i.e. OneTime binding), and cannot guarantee that it will always work.

Cheers!

Anton A.

5/20/2010 9:34:14 AM #

Pingback from 314.an74.com

Gl450 Molding, E 450 Econoline Super Duty Price Replacement Headlight Assembly Abs Plastic

314.an74.com

5/27/2010 1:48:35 AM #

Is binding to an element's property supported? If so, I can't get it to work...

<ScrollViewer x:Name="ScrollViewer">
...
<Grid ...>
<binding:BindingUtil.MultiBindings>
                            <binding:MultiBindings>
                                <binding:MultiBinding TargetProperty="Width" Converter="{StaticResource GridPlotSizeMultiConverter}">
                                    <binding:BindingCollection>
                                        <Binding ElementName="ScrollViewer" Path="ViewportWidth"/>
...

This binding never gets notified.
Any clues?

Thanks

Ben

6/27/2010 7:23:55 PM #

Hi Stefan,

Thanks for sharing - Can this solution do this:

I want to do a String Format (from a resource localisation file) and replace the values like this (this code works in SL4 for a single bind value)
<TextBlock Name="lblTotals" Text="{Binding TotalItems, StringFormat='You have \{0\} items in total.'}" />

Is it possible to output something similar with your solution, but with multiple bindings, like:
<TextBlock Name="lblTotals" Text="{Binding TotalItems, StringFormat='You have \{0\} items and \{0\} products in total'}" />

I downloaded and tried it but StringFormat was not recognised.

Thanks for any guidance...

Rodney

Add comment




biuquote
  • Comment
  • Preview
Loading



About the author

Stefan Olson is the Managing Director of Olson Software.  He has been developing software using Microsoft Technologies for nearly 20 years.

He is currently working on building the next generation Virtual Tour software in WPF and Silverlight for www.palacevirtualtours.com.

Tag cloud