I need to display the following using WPF databinding (the values change). Headers must be bold, the info lines are normal text. If info for a given header does not exist, I want to collapse that section, including the header. I prefer all the data (header and info items) be in one formatted string that can line break where I want.
Header1:
My info 1
My info 2
Header2:
My info 3
My info 4
If you want to do the bolding in a style I think your best bet would be to break your string up and use
TextBlocks
within aStackPanel
within anExpander
.Alternatively you could do it in a
RichTextBox
with your whole string, but I think your string would have to contain the<bold></bold>
tags.One more approach to try. Use TextBlock.Inlines. Then bind your model to the TextBlock, and either in custom value converter or via custom attached property parse your model to populate TextBlock's inlines.
Here is an example of Attached property that takes Text string and makes every second word bold:
This is not a production quality code, and it's taken from Silverlight demo, but you get the idea.
Hope this helps.
Cheers, Anvaka.