.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> Silverlight >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Trim Text in Silverlight 4 Using VS 2010

Posted By:Diptimaya Patra       Posted Date: May 10, 2010    Points: 25    Category: Silverlight    URL: http://www.dotnetspark.com  

Trim Text in Silverlight 4 Using VS 2010. In Silverlight 4, a property called TextTrimming is added to TextBlock, which will help the TextBlock to Trim a string up to a defined width
 

Introduction

In Silverlight 4, a property called TextTrimming is added to TextBlock, which will help the TextBlock to Trim a string up to a defined width. In this article we will see how this feature works.

Creating Silverlight Project

Fire up Visual Studio 2010 and create a new Silverlight Application Project. Name it as TextTrimminginSL4.

TextTrimmingWPF1.gif

We will look at some TextBlocks to see how TextTrimming works in Silverlight 4.


The above TextBlock is a normal TextBlock whose Width is set to Auto by default.

In design view it would look like following.

TextTrimmingWPF3.gif

Now let's examine another TextBlock whose Width is set to 290.

In design view, the above TextBlock looks like the following.

TextTrimmingWPF5.gif

Now we have a TextBlock whose Width is set to 150 and whose TextTrimming property is set to "WordEllipsis".


In design view it would render text as shown below.

TextTrimmingWPF7.gif

Let's run the application and resize the Browser Window.

You will see The TextBlock which has the TextTrimming property set to "WordEllipsis" will trim the width of the fully rendered string to fit into the width described by the Width property of the TextBlock control.

Without TextTrimming the width of a TextBlock whose content exceeds the width of the control, the TextBlocks view looks like the top line of the diagram below.  When we set the TextTrimming property of a TextBlock whose content exceeds the width of the control, the TextBlock View produces the ellipse shown in the last line of the diagram.


TextTrimmingWPF8.gif


Hope this article helps you understand how to take advantage of text trimming in your Silverlight Application.

You can also download the sample project used in above example.

 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend