Can we concat two properties in data binding?
If you want to show, say FirstName
and LastName
, in a single TextBlock
, then you can do like this:
<TextBlock>
<Run Text="{Binding FirstName}" />
<Run Text=" " /> <!-- space -->
<Run Text="{Binding LastName}" />
</TextBlock>
Now, the TextBlock's Text
property will be "Sachin Tendulkar"
and will be displayed if:
FirstName = Sachin
LastName = Tendulkar
Hope that helps.
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} , {1}">
<Binding Path="data1" />
<Binding Path="data2" />
</MultiBinding>
</TextBlock.Text>
data1 and data2 are string properties which are binded.
Like alpha-mouse suggests MultiBinding won't work out of the box, but this guy has thrown something together that might help:
http://www.olsonsoft.com/blogs/stefanolson/post/Improvements-to-Silverlight-Multi-binding-support.aspx
If that seems a bit rogue, then maybe try putting a combined value property on your object as a helper for the Binding mechanism, like:
public string FullName {
get { return this.FirstName + " " + this.LastName; }
}
It is possible in WPF with the help of MultiBinding and StringFormat. But not in Silverlight unfortunately.