How to create an expandable textblock in Silverlight

377 views Asked by At

Right now I have a datatemplate that wraps several textblock elements inside of a StackPanel. The textblocks specify information about the bound item, such as the name, description, and a few other properties.

I'm running into the problem where I feel each item in my ListBox (which consumes the datatemplate mentioned above) is displaying too much information. I want to condense it down a little bit and only display extra information if the user clicks on it.

QUESTION: How can I setup my datatemplate to only display the textblock that will display the name of the item, and if the user clicks the name it expands to show the other textblocks? I'm just looking for a painless way to implement this.

Thanks

1

There are 1 answers

0
ColinE On

I think Zortkun's suggestion of using a tooltip is a good one. A while back I wrote an attached behaviour that automatically moves a TextBlock's text into a tooltip if it is too long:

http://www.scottlogic.co.uk/blog/colin/2011/01/showing-tooltips-on-trimmed-textblock-silverlight/

It is used as follows:

<TextBlock Text="In Hertford, Hereford, and Hampshire, hurricanes hardly ever happen"
            util:TextBlockUtils.AutoTooltip="True"/>