Silverlight tip – Dynamic TextBlock

Posted by Corey on September 14, 2009 at 5:11 pm.

image

Problem: You need text to dynamically add elipses, "…",  to the end of a sentence.  The difficulty is how do you detect the actual length of the string.  All characters are not created the same.  Ten i’s != ten m’s.

Solution: Robby Ingebretsen at NerdPlusArt.com (and of Kaxaml fame) has a dynamic control that does just this.  http://blog.nerdplusart.com/archives/texttrimming-textblock-for-silverlight.

The solution is very Elegant.  Robby wraps a TextBlock in a Content control then manipulates the Text inside based on the size.  Best of all…he as post code and an example.  Thanks Robby.

2 Responses to “Silverlight tip – Dynamic TextBlock”

  • After reading your previous entry, I think what I like best about this post is that you’re simply giving a succinct summary of someone else’s solution. You don’t have to worry about a super-lengthy and drawn-out writeup of a problem/solution you took weeks to figure out, but you still get to help the community by referencing someone else’s work. Nice job! I’ll definately be using this at some point.

  • Thanks Ben, that’s exactly what I’m aiming for.

Leave a Reply