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.
Unfortunately silverlight is missing a few pieces that WPF has that can handle this. I would probably go the route of using a value converter that you can pass the class that contains the Title and Author to format the text.
Here’s the code:
And some XAML:
The downside to this way is that you won’t get the text to update if the properties change (ie you implement INotifyPropertyChanged) since the field is bound to the class.
As suggested in the comments on the question, you could also create a third property that combines them. This would get around having to use multibindings or value converters.