Bind textblock to two properties

Skoder picture Skoder · Jun 15, 2011 · Viewed 13.1k times · Source

I have a Textblock that is bound to a property in the ItemsSource collection. I'd like to display two properties from that class in the same textblock, but it seems I can only perform one binding at a time. I currently have this:

Text="{Binding Title}"

but I want I want to append another property, so in theory it would be:

Text="{Binding Title - Author}" 

with the output looking like "Shakespeare - Romeo and Juliet". I've tried adding a comma, another binding and other things, but they all result in an exception being thrown (e.g. Unknown attribute Text on element TextBlock).

Both properties comes from the same class, so I won't need to have two data sources.

Answer

Jasper Manickaraj picture Jasper Manickaraj · Nov 2, 2012

Use this one.. It will work Perfectly.

<TextBlock>
    <Run Text="{Binding Title}"></Run>
    <Run Text=":"></Run>
    <Run Text="{Binding Author}"></Run> 
</TextBlock>

the output will be like this,

OOPS:Balagurusamy