14 Sep

Silverlight tip – Dynamic TextBlock

Category:General PostTag: :


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.