Multi-binding Silverlight

Does anyone know if it is possible to make a binding and (if not how to achieve the same effect) on the same property using more than one binding in the form of a template

i.e. Text block with text associated in the expression

"{Binding Path=Contact.Title} {Binding Path=Contact.Firstname} {Binding Path=Contact.Surname}" 

all in one text property

+4
source share
5 answers

I had a similar problem that led me to a blog article Colin Eberhardt wrote:

http://www.scottlogic.co.uk/blog/wpf/2009/06/silverlight-multibindings-how-to-attached-mutiple-bindings-to-a-single-property/

It works very well, although I made some adjustments according to the specific scenario that I was watching, it was certainly useful to get multi-linking back.

+4
source

Not so easy:

 <TextBlock> <Run Text="{Binding Path=Contact.Title}"/> <Run Text="{Binding Path=Contact.Firstname}"/> <Run Text="{Binding Path=Contact.Surname}"/> </TextBlock> 
+6
source

AFAIK is impossible.

This is one reason to follow the MVVM pattern to create an intermediate view that reflects the data in the format you really want to represent, so you must create the fullname property of this class that would be a concatenation of these fields and then bind to it.

+3
source

Value converters are one of the solutions for binding to multiple values: http://timheuer.com/blog/archive/2008/07/30/format-data-in-silverlight-databinding-valueconverter.aspx#11262

In this scenario, you bind the TextBlock Text property to a Contact object and specify the custom value converter that you created. The converter can format strings based on property values.

+1
source

I do not think that this can be done directly in haml. I would really love several bindings to one property.

What I learned, however, is that you can do something similar to this using a couple of different strategies:

Using Stackpanel:

 <StackPanel Orientation="Horizontal"> <TextBlock Text="Hello, "/> <TextBlock Text="{Binding Contact.Title}"/> <TextBlock Text="{Binding Contact.Firstname}"/> <TextBlock Text="{Binding Contact.Surname}"/> <TextBlock Text="!"/> </StackPanel> 

Converter use:

 <TextBlock Text="{Binding Contact, Converter={StaticResource ContactNameConverter}}"/> 

Additional information about converters

+1
source

All Articles